-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch_91_arraylist.java
32 lines (31 loc) · 1.13 KB
/
ch_91_arraylist.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.ArrayList;
public class ch_91_arraylist {
public static void main(String[] args) {
ArrayList<Integer> li = new ArrayList<>();
ArrayList<Integer> bi = new ArrayList<>();
li.add(1);
li.add(2);
li.add(3);
li.add(4);
li.add(5);
li.remove(0); // remove at index 4
// bi list
bi.add(10);
bi.add(10);
bi.add(10);
li.addAll(0, bi); // at 0 index
li.remove(1); // removes index 1 element
for (Integer i : li) {
System.out.print(i + " ");
}
bi.clear();
System.out.println("\nbi.isEmpty() : " + bi.isEmpty());
System.out.println("li.size() : " + li.size());
System.out.println("li.contains(100) : " + li.contains(100));
System.out.println("li.indexOf(10) : " + li.indexOf(10)); // lowerbound
System.out.println("li.indexOf(200) : " + li.indexOf(200));
System.out.println("li.lastIndexOf(10) : " + li.lastIndexOf(10)); // upperbound
System.out.println("li.isEmpty() : " + li.isEmpty());
li.clear(); // clears the list
}
}