-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathArrayListDemo.java
More file actions
70 lines (63 loc) · 1.7 KB
/
ArrayListDemo.java
File metadata and controls
70 lines (63 loc) · 1.7 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
class Song
{
double price;
String name;
String albumName;
int duration;
}
public class ArrayListDemo {
// CRUD
// 1. Create 2. Read 3. Update 4. Delete
// 5. Search 6. Sort
public static void main(String[] args) {
// Add / Delete Operation Frequent
LinkedList<String> linkedList = new LinkedList<>();
linkedList.add("amit");
linkedList.addFirst("ram");
linkedList.addLast("shyam");
linkedList.removeLast();
linkedList.removeFirst();
linkedList.remove(0);
ArrayList<String> l = new ArrayList<>();
List<String> l2 = Collections.synchronizedList(l);
l2.add("amit");
// synchronized (l) {
// l.add("ram");
// }
// Synchronized
// More Methods (Old + New ArrayList)
Vector<String> vector = new Vector<>(); // Legacy Class (1.2)
vector.addElement("ram");
vector.add("shyam");
int e ;
Song song ;
ArrayList<Song> songs = new ArrayList<Song>();
// TODO Auto-generated method stub
ArrayList<String> songList = new ArrayList<String>();
songList.add("Boom Boom"); // Create
songList.add("Bang bang");
//System.out.println(songList);
//System.out.println(songList.toString());
songList.add(1,"It's My life");
songList.set(0, "I Got the Power"); // Update
//songList.remove(0); // Delete
System.out.println(songList); // Read
boolean isFound = songList.contains("Bang bang"); // Searching
if(isFound){
System.out.println("Song Found..");
}
else
{
System.out.println("Song Not Found..");
}
// Sorting
Collections.sort(songList);
System.out.println("After Sort");
System.out.println(songList);
}
}