Repository navigation
Expand file tree
/
Copy pathOfficeNov5.java
More file actions
129 lines (94 loc) · 3.44 KB
/
Copy pathOfficeNov5.java
File metadata and controls
129 lines (94 loc) · 3.44 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package Day22.java;
import java.util.*;
public class OfficeNov5 {
public static void main(String[] args) {
// Collections in java
// Answer --->> : Collection has multiple types and I am using the arrylist and also I can use set and map
// differences between collection types
// set vs list vs map
Set<Integer> set1 = new LinkedHashSet<>();
set1.add(1);
set1.add(2);
set1.add(3);
set1.add(4);
set1.add(1);
set1.add(5);
set1.add(10);
set1.add(6);
set1.add(null);
set1.add(null);
System.out.println("set1 ----> "+set1);
/* Set :
Does not allow duplicates
Able to store just one null value
Set has multiple print types
Set vs map
Able to store just a values in the set
*/
List<Integer> list1 = new ArrayList<>();
list1.add(5);
list1.add(2);
list1.add(3);
list1.add(4);
list1.add(1);
list1.add(5);
list1.add(10);
list1.add(6);
list1.add(null);
list1.add(null);
System.out.println("list1 ---> "+list1);
/*
List :
Allow the duplicates
Able to store multiple null value
Able to print with first in first out
List vs map
Able to store just a value in the list
*/
System.out.println("Linked hash map --------->>>>> ordered by how you put in the map ");
Map<String , String> map1 = new LinkedHashMap<>();
map1.put("James" , "USA");
map1.put("Carly" , "London");
map1.put("Steven" , "USA");
map1.put("David" , "Mexico");
map1.put("Lionel" , "Italy");
map1.put("Andres" , "Spain");
System.out.println(map1);
// --------------------
System.out.println("HashMap ----------->>>>>>>>> print randomly");
Map<String , String> map2 = new HashMap<>();
map2.put("James" , "USA");
map2.put("Carly" , "London");
map2.put("Steven" , "USA");
map2.put("David" , "Mexico");
map2.put("Lionel" , "Italy");
map2.put("Andres" , "Spain");
System.out.println(map2);
System.out.println("TreeMap ----------->>>>>>>>> is print by alphabet (String ) or smaller number to bigger number(Integer) ");
Map<String , String> map3 = new TreeMap<>();
map3.put("James" , "USA");
map3.put("Carly" , "London");
map3.put("Steven" , "USA");
map3.put("David" , "Mexico");
map3.put("Lionel" , "Italy");
map3.put("Andres" , "Spain");
System.out.println(map3);
// hashmap and linkedhashmap are same ?
/*
Map
Able to store key and value pair
Key should be unique
Value can be duplicated
different print types -> linked hash map , hashmap , tree map
*/
// treeset vs LinkedHashset vs hashset
Set<Integer> LinkedHashSet1 = new LinkedHashSet<>();
LinkedHashSet1.add(1);
LinkedHashSet1.add(3);
LinkedHashSet1.add(5);
LinkedHashSet1.add(2);
LinkedHashSet1.add(4);
System.out.println("Linked hash set -------->> "+LinkedHashSet1);
// set methods --->> add , clear , contains , isEmpty , remove , size
}
}