Map
✅ Map
key➕valuekey: uniquevalue: duplication possible- no order
☑️ HashMap
key➕value- add, search value:
O(1) - no order
- get all: random
O(1)- must override
hashCode()andequals()to use hash index
1
2
3
4
5
6
7
8
9
10
11
Map<String, Integer> studentMap = new HashMap<>();
studentMap.put("student1", 90);
//get value
studentMap.get("student1");
//get keys
Set<String> keys = studentMap.keySet();
//get values
Collection<Integer> values = studentMap.values();
//get key ➕ value
Set<Map.Entry<String, Integer>> entries = studentMap.entrySet();
☑️ LinkedHashMap
HashMap➕linkedList(order)- add, search value:
O(1) - get all: input order
O(1)
☑️ TreeMap
HashMap➕tree- get all:
keyascending order O(logN)
✅
✅
✅
✅
✅
✅
✅
✅
✅
This post is licensed under CC BY 4.0 by the author.
