forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arraylist
51 lines (32 loc) · 1.76 KB
/
Arraylist
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
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.ArrayList;
public class arraylist {
public static void main(String[] args)
{
ArrayList<String> citylist = new ArrayList <String>();
citylist.add("hedrabad");
citylist.add("pune");
citylist.add("rajkot");
citylist.add("ahemdabad");
citylist.add("mumbai");
citylist.add("rajshthan");
// objectname.contains() method is use to check weather the element is present or nor
// its return only true or flase value
System.out.println("the delhi is present in this list "+citylist.contains("delhi"));
System.out.println("the mumbai is present in this list "+citylist.contains("mumbai"));
// objectname.size() is to use to find the size of the our arraylist
System.out.println("the size of this arraylist is "+citylist.size());
//objectname.indexOf is to use to find the index of the element .
System.out.println("location of the city mumbai is "+citylist.indexOf("mumbai"));
// objectname.isEmpty is to use check the weather the list is empty or not
System.out.println("let's check the weather the list is empty or not : "+citylist.isEmpty());
// objectname.set(index,value) is to use replace the particular value in the list
citylist.set(1,"kerla");
// objectname.remove() is to use to delete the value which is present in the arraylist
citylist.remove(1);
citylist.remove("mumbai");
// objectname.get(index) is to use to find the value at particular index
System.out.println("the value of the index 3 is "+citylist.get(3));
// objectname.tostring() is to use for the printing all over list
System.out.println(citylist.toString());
}
}