Questions tagged [guava]

Google's Core Java Library for Java and Android development.

Guava

Guava is an open-source Java library that aims to make working in the Java language more pleasant and more productive.

It contains several core libraries that Google relies on in their Java-based projects: collections, caching, primitives support, concurrency libraries, common annotations, basic string processing, I/O, mathematics, etc.

Resources

3369 questions
215
votes
5 answers

Google Guava vs. Apache Commons

I was looking for a bidirectional map implementation in Java, and stumbled upon these two libraries: Google Guava (formerly "Google Collections") Apache Commons Collections Both are free, have the bidirectional map implementation that I was…
Joonas Pulakka
  • 34,943
  • 25
  • 103
  • 165
152
votes
3 answers

initializing a Guava ImmutableMap

Guava offers a nice shortcut for initializing a map. However I get the following compiler error (Eclipse Indigo) when my map initializes to nine entries. The method of(K, V, K, V, K, V, K, V, K, V) in the type ImmutableMap is not applicable for…
user903724
  • 2,698
  • 3
  • 20
  • 27
149
votes
9 answers

How can I generate a list or array of sequential integers in Java?

Is there a short and sweet way to generate a List, or perhaps an Integer[] or int[], with sequential values from some start value to an end value? That is, something shorter than, but equivalent to1 the following: void List
BeeOnRope
  • 51,419
  • 13
  • 149
  • 309
139
votes
11 answers

Interface/enum listing standard mime-type constants

I am looking among the standard libraries (like apache commons, jax, jboss, javax) for an interface or enum that lists the values of all the standard mime-type (aka content-type). This interface should not be encumbered with too deep with other…
Blessed Geek
  • 19,240
  • 21
  • 96
  • 165
131
votes
8 answers

The Guava library: What are its most useful and/or hidden features?

I have had a quick scan of the Guava API and the new collection types it provides(Multimap and BiMap for example appear useful) and I am thinking of including the library in the project(s) I work on. However, I also have a reticence to include…
NimChimpsky
  • 43,542
  • 55
  • 186
  • 295
126
votes
1 answer

Is it a good idea to use Google Guava library for Android development?

I am involved in the development of Android application which is a rather "thick" mobile client for a Web service. It heavily communicates with the server but also has a lot of inner logic too. So, I decided to use some features of Google Guava…
Oleksandr Karaberov
  • 12,223
  • 10
  • 39
  • 68
123
votes
3 answers

What are the big improvements between guava and apache equivalent libraries?

We currently use apache collections, string utils, etc. I need to decide if we should switch from the apache foundations implementation. The important criteria is ease of developers use. Performance/memory usage is not yet an important issue for us.…
Pat
  • 5,601
  • 5
  • 31
  • 50
123
votes
19 answers

Map implementation with duplicate keys

I want to have a map with duplicate keys. I know there are many map implementations (Eclipse shows me about 50), so I bet there must be one that allows this. I know it's easy to write your own map that does this, but I would rather use some existing…
IAdapter
  • 55,820
  • 69
  • 166
  • 236
115
votes
15 answers

builder for HashMap

Guava provides us with great factory methods for Java types, such as Maps.newHashMap(). But are there also builders for java Maps? HashMap m = Maps.BuildHashMap. put("a",1). put("b",2). build();
Elazar Leibovich
  • 30,136
  • 27
  • 116
  • 161
115
votes
5 answers

Combine multiple Collections into a single logical Collection?

Assume, I have a constant number of collections (e.g. 3 ArrayLists) as members of a class. Now, I want to expose all the elements to other classes so they can simply iterate over all elements (ideally, read only). I'm using guava collections and I…
newgre
  • 5,055
  • 4
  • 28
  • 41
109
votes
9 answers

Guava equivalent for IOUtils.toString(InputStream)

Apache Commons IO has a nice convenience method IOUtils.toString() to read an InputStream to a String. Since I am trying to move away from Apache Commons and to Guava: is there an equivalent in Guava? I looked at all classes in the…
Sean Patrick Floyd
  • 274,607
  • 58
  • 445
  • 566
109
votes
4 answers

UnmodifiableMap (Java Collections) vs ImmutableMap (Google)

Context I need to return a reference to a map that I'm using for a data cache, and I'd like to make sure nobody can modify their reference. Question I've seen lots of references to UnmodifiableMap and ImmutableMap online, but I don't see anything…
John Humphreys - w00te
  • 32,140
  • 30
  • 125
  • 230
103
votes
7 answers

Google Guava isNullOrEmpty for collections

I see that Guava has isNullOrEmpty utility method for Strings Strings.isNullOrEmpty(str) Do we have anything similar for Lists? Something like Lists.isNullOrEmpty(list) which should be equivalent to list == null || list.isEmpty() Also, do we have…
Ramesh
  • 3,581
  • 5
  • 20
  • 28
102
votes
4 answers

Predicate in Java

I am going through the code which uses Predicate in Java. I have never used Predicate. Can someone guide me to any tutorial or conceptual explanation of Predicate and its implementation in Java?
srikanth
  • 1,191
  • 2
  • 8
  • 11
98
votes
6 answers

Bi-directional Map in Java?

I have a simple integer-to-string mapping in Java, but I need to be able to easily retrieve string from integer, and also integer from string. I've tried Map, but it can retrieve only string from integer, it's one way: private static final…
Danijel
  • 6,584
  • 16
  • 58
  • 109
1
2 3
99 100