本文介绍了Google Guava与Apache Commons的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找使用Java的实现,并偶然发现了这两个库:

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



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

两者都是免费的,有我正在寻找的双向地图实现(Apache中的BidiMap,Google中的BiMap),非常接近相同的大小(Apache 493 kB,谷歌499 kB)并且在各方面都与我非常相似。

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.

推荐答案

In我认为更好的选择是(以前称为Google收藏):

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


  • 它更现代(有泛型)

  • 它完全遵循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也是一个很好的库,但它很长时间没能提供一个支持泛型的vers离子(在我看来,这是集合API的主要缺点)并且通常似乎处于维护/不做太多工作的模式。

Apache Commons Collections is a good library as well, but it has long failed to provide a generics-enabled version (which is a major drawback for a collections API in my opinion) and generally seems to be in a maintenance/don't-do-too-much-work-on-it mode .

如果下载大小/内存占用/代码大小是问题然后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.

这篇关于Google Guava与Apache Commons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 15:38