-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayList8.java
38 lines (31 loc) · 982 Bytes
/
ArrayList8.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
33
34
35
36
37
38
import java.util.*;
public class ArrayList8{
public static void main(String[] agrs){
ArrayList <String> al = new ArrayList<String>();
al.add("Ravi");
al.add("Vijay");
al.add("Ajay");
al.add("Anuj");
al.add("Gaurav");
System.out.println("Intial list.." + al);
//Removing by name
al.remove("Vijay");
System.out.println("After invoking remove(object) method : " +al);
//Remove on the basis of position
al.remove(0);
System.out.println("After invoking remove(index) method :" + al);
//Creating another ArrayList
ArrayList<String> al2 = new ArrayList<String>();
al2.add("Ravi");
al2.add("Harpreet");
//Adding all the ele
al.addAll(al2);
System.out.println("Updated list :" + al);
al.removeAll(al2);
System.out.println("After invoking removeAll() method : " +al);
al.removeIf(str -> str.contains("Ajay"));
System.out.println("After invoking removeIf() method :" +al);
al.clear();
System.out.println("After invoking clear() method : " +al);
}
}