Guava - MultiSet 原理与实战

Guava - MultiSet 原理与实战

  • 原文地址:
  • 原文作者:
  • 本文永久链接:
特别说明

当前文章内容迁移中,如有问题,请提交 issues 谢谢~~

函数签名:

@GwtCompatible
public interface Multiset<E> extends Collection<E> &#123;&#125;

MultiSet 可以跟踪每种对象的数量,所以可以用来进行数字统计。

常规的 Java 方法:

 Map<String, Integer> map1 = new HashMap<>();

 List<String> wordList = Arrays.asList("the","b");
 for (String word : wordList) &#123;
      Integer count =  map1.get(word);
      map1.put(word,(count == null)?1:count +1);
    &#125;
    Integer count = map1.get("the");
    System.out.println(count);//1

如果使用 MultiSet

参考文章
Prev:
java-basic-collection-linked-blocking-queue
Next:
java-basic-condition
Contents of this article
Contents of this article