- Maps.uniqueIndex()将列表转换为map
1 //iterator各个元素作为Map.values, key为Function.apply返回值 2 Maps.uniqueIndex(ps.iterator(), new Function<Person, String>() { 3 @Override 4 public String apply(Person p) { 5 return p.getName(); 6 } 7 });
- Maps.asMap(),<K, V>和Maps.uniqueIndex()相反
1 Maps.asMap(ps, new Function<Person, String>() { 2 @Override 3 public String apply(Person p) { 4 return p.getName(); 5 } 6 });
- Maps Transform API:
Maps.transformEntries(map, new Maps.EntryTransformer<String, Boolean, String>() { @Override public String transformEntry(String key, Boolean value) { return value ? "yes" : "no"; } }); 将Map<String, Boolean> --> Map<String, String>, 其他的还有Maps.transformValues转换值
时间: 2024-11-09 00:07:50