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

3540 questions
219
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
  • 36,252
  • 29
  • 106
  • 169
179
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
  • 60,350
  • 16
  • 207
  • 386
173
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
  • 21,058
  • 23
  • 106
  • 176
170
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,956
  • 4
  • 24
  • 27
156
votes
11 answers

Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules guava-20.0.jar (com.google.guava:guava:20.0)

When I use implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0' in my app/build.gradle, I get this error: Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules guava-20.0.jar…
Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103
136
votes
20 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
  • 62,595
  • 73
  • 179
  • 242
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
  • 46,453
  • 60
  • 198
  • 311
130
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
  • 32,750
  • 33
  • 122
  • 169
130
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,573
  • 10
  • 43
  • 70
126
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,761
  • 5
  • 34
  • 50
120
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,245
  • 4
  • 31
  • 41
119
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
  • 8,198
  • 18
  • 69
  • 133
118
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
  • 37,047
  • 37
  • 155
  • 255
112
votes
9 answers

Get empty string when null

I want to get string values of my fields (they can be type of long string or any object), if a field is null then it should return empty string, I did this with guava; nullToEmpty(String.valueOf(gearBox)) nullToEmpty(String.valueOf(id)) ... But…
Spring
  • 11,333
  • 29
  • 116
  • 185
111
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,841
  • 5
  • 22
  • 28
1
2 3
99 100