-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.java
56 lines (45 loc) · 1.55 KB
/
maps.java
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
import java.util.*;
public class hello {
public static void main(String[] args) {
// TODO Auto-generated method stub
TreeMap <Integer,String> map = new TreeMap<>();
map.put(-12,"srini");
map.put(5,"srini1");
map.put(1,"srini2");
map.put(10,"srini3");
map.put(-1,"srin4i");
map.put(9,"srini3");
map.put(-2,"srin4i");
map.put(6,"srini3");
map.put(-3,"srin4i");
System.out.println(map);
// o/p {-12=srini, -3=srin4i, -2=srin4i, -1=srin4i, 1=srini2, 5=srini1, 6=srini3, 9=srini3, 10=srini3}
// sorted tree #### map because it store in key value pair
HashMap <Integer,String> map = new HashMap<>();
map.put(-12,"srini");
map.put(5,"srini1");
map.put(1,"srini2");
map.put(10,"srini3");
map.put(-1,"srin4i");
map.put(9,"srini3");
map.put(-2,"srin4i");
map.put(6,"srini3");
map.put(-3,"srin4i");
System.out.println(map);
// o/p {-1=srin4i, 1=srini2, -2=srin4i, -3=srin4i, 5=srini1, 6=srini3, 9=srini3, 10=srini3, -12=srini}
// based hash dynamically changes maybes takes abs
LinkedHashMap <Integer,String> map = new LinkedHashMap<>();
map.put(-12,"srini");
map.put(5,"srini1");
map.put(1,"srini2");
map.put(10,"srini3");
map.put(-1,"srin4i");
map.put(9,"srini3");
map.put(-2,"srin4i");
map.put(6,"srini3");
map.put(-3,"srin4i");
System.out.println(map);
// o/p{-12=srini, 5=srini1, 1=srini2, 10=srini3, -1=srin4i, 9=srini3, -2=srin4i, 6=srini3, -3=srin4i}
// maintain the insertion order maybe uses a linked list
}
}