BiMap Interface
A BiMap is a special kind of map which maintains an inverse view of the map while ensuring that no duplicate values are present in the map and a value can be used safely to get the key back.
package org.fool.guava.collections;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
public class BiMapTest {
public static void main(String[] args) {
BiMap<Integer, String> empIDNameMap = HashBiMap.create();
empIDNameMap.put(new Integer(101), "Mahesh");
empIDNameMap.put(new Integer(102), "Sohan");
empIDNameMap.put(new Integer(103), "Ramesh");
System.out.println(empIDNameMap.inverse().get("Mahesh"));
}
}
output
101
本文深入探讨了BiMap接口的特性,包括其保持逆视图的功能和无重复值的特性,并通过示例展示了如何使用BiMap接口进行操作。
144

被折叠的 条评论
为什么被折叠?



