Skip to content

Commit e0ef465

Browse files
Arraylist-java
1 parent f121c08 commit e0ef465

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Arraylist

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
import java.util.ArrayList;
3+
4+
public class arraylist {
5+
6+
public static void main(String[] args)
7+
{
8+
ArrayList<String> citylist = new ArrayList <String>();
9+
10+
citylist.add("hedrabad");
11+
citylist.add("pune");
12+
citylist.add("rajkot");
13+
citylist.add("ahemdabad");
14+
citylist.add("mumbai");
15+
citylist.add("rajshthan");
16+
17+
// objectname.contains() method is use to check weather the element is present or nor
18+
// its return only true or flase value
19+
20+
System.out.println("the delhi is present in this list "+citylist.contains("delhi"));
21+
System.out.println("the mumbai is present in this list "+citylist.contains("mumbai"));
22+
23+
// objectname.size() is to use to find the size of the our arraylist
24+
25+
System.out.println("the size of this arraylist is "+citylist.size());
26+
27+
//objectname.indexOf is to use to find the index of the element .
28+
29+
System.out.println("location of the city mumbai is "+citylist.indexOf("mumbai"));
30+
31+
// objectname.isEmpty is to use check the weather the list is empty or not
32+
33+
System.out.println("let's check the weather the list is empty or not : "+citylist.isEmpty());
34+
35+
// objectname.set(index,value) is to use replace the particular value in the list
36+
37+
citylist.set(1,"kerla");
38+
39+
// objectname.remove() is to use to delete the value which is present in the arraylist
40+
41+
citylist.remove(1);
42+
citylist.remove("mumbai");
43+
44+
// objectname.get(index) is to use to find the value at particular index
45+
46+
System.out.println("the value of the index 3 is "+citylist.get(3));
47+
48+
// objectname.tostring() is to use for the printing all over list
49+
System.out.println(citylist.toString());
50+
}
51+
}

0 commit comments

Comments
 (0)