Guava BiMap
BiMap主要的就是用于key,value的互相映射,获取相互的结果,还保证值value是唯一的,key相同覆盖原来值。
举例:
BiMap<Integer, String> empIDNameMap = HashBiMap.create();
empIDNameMap.put(new Integer(101), "Mahesh");
empIDNameMap.put(new Integer(102), "Sohan");
empIDNameMap.put(new Integer(103), "Ramesh");
//empIDNameMap.put(new Integer(104), "Mahesh"); // 报错: java.lang.IllegalArgumentException: value already present: Mahesh
System.out.println(empIDNameMap.inverse().get("Mahesh")); //101