Java LinkedHashMap Example
LinkedHashMap keeps the order-intersection
LinkedHashMap use map and DoubleLinkedList to implement it.
LinkedHashMap map = new LinkedHashMap();
map.put(1, "dog");
map.put(2, "cat");
map.put(3, "cow");
Set set = map.keySet();
for(Integer k : set){
Print.p(map.get(k));
}
TreeMap in Java, $\log(n)$ contains, insert, implements in Red-Black tree
class Student{
String name;
Integer age;
public Student(String name, Integer age){
this.name = name;
this.age = age;
}
}
class CompareTree implements Comparator{
public int compare(Student s1, Student s2){
return s1.name.compareTo(s2.name);
}
}
TreeMap map = new TreeMap<>(new CompareTree());
map.put(new Student("David", 3), "good");
map.put(new Student("Michael", 4), "bad");