-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashingJCF.java
More file actions
68 lines (50 loc) · 1.81 KB
/
HashingJCF.java
File metadata and controls
68 lines (50 loc) · 1.81 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
public class HashingJCF {
public static void main(String[] args) {
/* ************* HASHSET **************
HashSet<Integer> set = new HashSet<>();
set.add(1);
set.add(2);
set.add(3);
System.out.println(set);
//search
if(set.contains(1)){
System.out.println("Set contains 1");
}
if(!set.contains(6)){
System.out.println("Set does not contain 6");
}
set.remove(1);
if(!set.contains(1)){
System.out.println("Deleted");
}
System.out.println(set);
//Iterator
Iterator it = set.iterator();
//hasnext and next function are used
while(it.hasNext()){
System.out.print(it.next() + " "); //order is not specified
}
*************** HASHSET END ******************* */
/* ************** HASHMAPS ********************
//for every pair ,we use hashmaps in java
// country, populat
HashMap< String , Integer > map = new HashMap<>(); //key and value structure
map.put("India" , 120); //insertion
map.put("USA" , 30);
map.put("China" , 150);
System.out.println(map); //unordered
map.put("China" , 180); //updates value
System.out.println(map);
//search
System.out.println(map.containsKey("China"));
System.out.println(map.get("India"));
//for each loop
// for(int val : set){ sout(val) }
//iteration -type e : colecti
for(Map.Entry<String , Integer> e : map.entrySet()){
System.out.println(e.getKey() + " ");
System.out.println(e.getValue() + " ");
}
******** END OF HASHMAPS *********** */
}
}