Created
April 20, 2015 14:25
-
-
Save roberto-filho/ae477dda31357b7c92cd to your computer and use it in GitHub Desktop.
Map to List with Guava
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cria um map | |
Map<String, String> m = Maps.newHashMap(); | |
// Aplica uma função ao entrySet() do map que transforma cada entry em um BasicNameValuePair | |
Iterable<BasicNameValuePair> transformed = Iterables.transform(m.entrySet(), new Function<Entry<String, String>, BasicNameValuePair>() { | |
public BasicNameValuePair apply(Entry<String,String> input) { | |
return new BasicNameValuePair(input.getKey(), input.getValue()); | |
}; | |
}); | |
// Cria uma lista de NameValuePair | |
List<BasicNameValuePair> list = newArrayList(transformed); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment