本文介绍了Apache Commons vs. Guava(以前称为“Google Collections”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中寻找实现,偶然发现了这两个库:

I was looking for a bidirectional map implementation in Java, and stumbled upon these two libraries:



  • (以前称为Google Collections)

  • Apache Commons Collections
  • Guava (formerly "Google Collections")

两者都是免费的,具有我正在寻找的双向地图实现在谷歌),令人惊讶的是几乎相同的大小(Apache 493 kB,谷歌499 kB)[ed。不再是真的!]看起来在所有方面非常相似我。

Both are free, have the bidirectional map implementation that I was looking for (BidiMap in Apache, BiMap in Google), are amazingly nearly the same size (Apache 493 kB, Google 499 kB) [ed.: no longer true!] and seem in all ways pretty similar to me.

我应该选择哪一个,为什么?是否有其他等效替代品(必须是免费的,至少有双向地图)?我正在使用最新的Java SE,所以不需要人为限制Java 5或类似的东西。

Which one should I choose, and why? Are there some other equivalent alternatives (must be free and have at least the bidirectional map)? I'm working with the latest Java SE, so no need to artificially limit to Java 5 or anything like that.

推荐答案

我的意见是更好的选择是(以前称为作为Google集合):

In my opinion the better choice is Guava (formerly known as Google collections):


  • 更现代(有泛型)

  • API要求

  • 积极维护

  • ,它的前身

  • it's more modern (has generics)
  • it absolutely follows the Collections API requirements
  • it's actively maintained
  • CacheBuilder and it's predecessor MapMaker are just plain awesome

Apache Commons Collections也是一个很好的库,但它很久没能提供泛型使能的版本这在我看来是一个集合API的一个主要的缺点),一般似乎是在维护/不做太多的工作模式.

如果下载大小/内存占用/代码大小是一个问题, Apache Commons Collections可能是一个更好的候选者,因为它是其他库的常见依赖。因此,在您自己的代码中使用它也可以无需添加任何额外的依赖关系。编辑:现在,这个特定的优点已经被部分破坏了,因为许多新库实际上依赖于Guava,而不是在Apache Commons Collections上。

If download size/memory footprint/code size is an issue then Apache Commons Collections might be a better candidate, since it is a common dependency of other libraries. Therefore using it in your own code as well could potentially be done without adding any additional dependencies. This particular "advantage" has been partially subverted by now, since many new libraries actually depend on Guava and not on Apache Commons Collections.

这篇关于Apache Commons vs. Guava(以前称为“Google Collections”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 13:16