Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0fb825a

Browse files
committed
Collection ArrayList Methods
1 parent212a6b0 commit0fb825a

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

‎Collection/ArrayListMethods.java‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
importjava.util.*;
2+
3+
classArrayListMethodsextendsArrayList{
4+
5+
publicstaticvoidmain(String[]args) {
6+
7+
ArrayListMethodsal =newArrayListMethods();
8+
9+
// 1) boolean add(E);
10+
al.add(10);
11+
al.add("Dhiraj");
12+
al.add("Dhiraj");
13+
al.add(20.5f);
14+
al.add(10);
15+
16+
System.out.println(al);
17+
18+
// 2) void add(int, E);
19+
20+
al.add(3,"Core2Web");
21+
System.out.println(al);
22+
23+
// 3) public int size();
24+
25+
System.out.println(al.size());
26+
27+
// 4) public boolean isEmpty();
28+
System.out.println(al.isEmpty());
29+
30+
// 5) boolean contains(Object);
31+
System.out.println(al.contains("Dhiraj"));
32+
System.out.println(al.contains(23));
33+
34+
// 6) int indexOf(Object);
35+
System.out.println(al.indexOf(10));
36+
37+
// 7) int lastIndexOf(Object);
38+
System.out.println(al.lastIndexOf(10));
39+
40+
// 8) E get(int);
41+
System.out.println(al.get(5));
42+
43+
// 9) E set(3,E);
44+
System.out.println(al.set(2,"Gadekar"));
45+
System.out.println(al);
46+
47+
ArrayListal2 =newArrayList();
48+
al2.add("salman");
49+
al2.add("shahrukh");
50+
al2.add("Amir");
51+
52+
// 10) boolean addAll(Collection);
53+
al.addAll(al2);
54+
System.out.println(al);
55+
56+
// 11) boolean addAll(int, Collection);
57+
al.addAll(3,al2);
58+
System.out.println(al);
59+
60+
// 12) void removeRange(int, int);
61+
al.removeRange(3,6);
62+
System.out.println(al);
63+
64+
// 13) E remove(int);
65+
System.out.println(al.remove(6));
66+
System.out.println(al);
67+
68+
// 14) boolean remove(Object);
69+
System.out.println(al.remove("Amir"));
70+
System.out.println(al.remove("salman"));
71+
System.out.println(al);
72+
73+
// 15) Object[] toArray();
74+
Objectarr[] =al.toArray();
75+
76+
for(Objectdata :arr) {
77+
78+
System.out.print(data +" ");
79+
}
80+
System.out.println();
81+
82+
// 16) boolean removeAll(Collection);
83+
System.out.println(al.removeAll(al2));
84+
System.out.println(al);
85+
86+
al2.add("Dhiraj");
87+
al2.add("Gadekar");
88+
al2.add(10);
89+
// 17) boolean retainAll(Collection);
90+
System.out.println(al.retainAll(al2));
91+
System.out.println(al);
92+
93+
// 18) int hashCode();
94+
System.out.println(al.hashCode());
95+
96+
// 19) Object clone();
97+
ArrayListal3 = (ArrayList)al.clone();
98+
System.out.println(al3);
99+
100+
// 20) boolean equals(Object);
101+
System.out.println(al);
102+
System.out.println(al3);
103+
System.out.println(al.equals(al3));
104+
105+
// 21) void clear();
106+
al.clear();
107+
System.out.println(al);
108+
}
109+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp