Skip to content

Instantly share code, notes, and snippets.

@roberto-filho
Created April 20, 2015 14:25
Show Gist options
  • Save roberto-filho/ae477dda31357b7c92cd to your computer and use it in GitHub Desktop.
Save roberto-filho/ae477dda31357b7c92cd to your computer and use it in GitHub Desktop.
Map to List with Guava
// 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