[Guava学习笔记]Collections: 集合工具类

我的技术博客经常被流氓网站恶意爬取转载。请移步原文:http://www.cnblogs.com/hamhog/p/3861431.html,享受整齐的排版、有效的链接、正确的代码缩进、更好的阅读体验。

集合工具类

 静态工厂方法

List<String> theseElements = Lists.newArrayList("alpha", "beta", "gamma");

Iterables

concat(Iterable<Iterable>) frequency(Iterable, Object) partition(Iterable, int)按大小分割 elementsEqual(Iterable, Iterable) unmodifiableIterable(Iterable)

Lists

partition(List, int)分割 reverse(List)逆序

Sets

union(Set, Set)并 intersection(Set, Set)交 difference(Set, Set)Set1-Set2 symmetricDifference(Set, Set)Set1并Set2-Set1交Set2

返回的是SetView,可以直接当Set用,也可以copyInto(Set) immutableCopy()

cartesianProduct(List<Set>)笛卡尔积 powerSet(Set)所有子集

Maps

Maps.uniqueIndex(Iterable,Function)创建唯一索引

Maps.difference(Map, Map) 返回的对象可以调用entriesInCommon() entriesDiffering() entriesOnlyOnLeft() entriesOnlyOnRight()

Multisets

containsOccurrences(Multiset sup, Multiset sub)<=则为true removeOccurrences(Multiset removeFrom, Multiset toRemove)移除一次 retainOccurrences(Multiset removeFrom, Multiset toRetain)确保每个元素的出现次数<=toRetain中

copyHighestCountFirst(Multiset)按出现次数降序

Multimaps

Multimaps.index(Iterable, Function)创建未必唯一的索引 invertFrom反转

Tables

transpose(Table<R, C, V>)行列反转

posted @ 2014-07-22 21:26  戴仓薯  阅读(1536)  评论(0编辑  收藏  举报