Contoh ArrayList<Integer>

Run Settings
LanguageJava
Language Version
Run Command
package pertemuan17; import java.util.ArrayList; import java.util.List; public class ContohArrayList { public static void main(String[] args) { // add(element), get(index), remove(index), set(index, element) // size() ArrayList<Integer> angka = new ArrayList<>(); // menambah elemen int a = 10; angka.add(a); angka.add(5); angka.add(25); angka.addAll(List.of(30, 15, 45, 60, 17, 47, 47, 88, 19, 40)); System.out.println("Jumlah: "+ angka.size()); // mengambil nilai int b = angka.get(2); System.out.println(b); System.out.println(angka.get(3)); System.out.println("----------"); for (int i=0; i<angka.size(); i++) { System.out.println(angka.get(i)); } // menghapus nilai (index ke 3) angka.remove(3); // merubah nilai (index 4, menjadi 44) angka.set(4, 44); System.out.println("----------"); for (int i=0; i<angka.size(); i++) { System.out.println(angka.get(i)); } } }
Editor Settings
Theme
Key bindings
Full width
Lines