forked from Krushna-Prasad-Sahoo/JavaCode-Hacktoberfest2021
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListOne.java
More file actions
Latest commit
38 lines (24 loc) · 1.05 KB
/
Copy pathArrayListOne.java
File metadata and controls
38 lines (24 loc) · 1.05 KB
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
packagepracticeDemo1;
importjava.util.ArrayList;
importjavax.xml.crypto.Data;
publicclassArrayListOne {
publicstaticvoidmain(String[] args) {
ArrayListw = newArrayList();
// ArrayList basically give 10 slots to store Data. As soon as you put 11th element it doubles the size of array
// i.e of 20 size. Similarly as soon as you put 21st element, again it doubles & makes size 40. Hence it's not so
// optimized. Also if you remove the 1st element of this , all other will be copied to the previous place.
// For all these reasons LinkedList is better choice than Array List.
w.add("hello");
w.add("there");
w.add("java");
System.out.println(w);
w.remove(1);
System.out.println(w);
//-----------------------------------------------------------------------------------------------
Stringitem1 = (String) w.get(1);
System.out.println(item1);
Objectitem2 = w.get(0);
System.out.println(item2);
// Array list is faster for retrieval but slower for data manipulation.
}
}