lists
//JDK
List<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
//Guava
List<String> list = Lists.newArrayList("a", "b", "c", "d");
Multiset(统计次数的set
Multiset<String> multiset = HashMultiset.create();
// 统计每次单词出现的次数
for (String word : words) {
multiset.add(word);
}
// 输出单词的输出次数
for (String word : multiset.elementSet()) {
multiset.count(word);
}
Multimap(多个value的map
Multimap<Integer, People> multimap = ArrayListMultimap.create();
// 统计同一年纪的 People 对象
for (People people : peopleList) {
multimap.put(people.getAge(), people);
}
// 输出统计结果
for (Integer key : multimap.keySet()) {
List<People> peoples = Lists.newArrayList(multimap.get(key));
System.out.println(peoples);
}
Bimap(双向map
BiMap<Integer, String> empIDNameMap = HashBiMap.create();
empIDNameMap.put(new Integer(101), "Mahesh");
empIDNameMap.put(new Integer(102), "Sohan");
empIDNameMap.put(new Integer(103), "Ramesh");
//Emp Id of Employee "Mahesh"
System.out.println(empIDNameMap.inverse().get("Mahesh"));