I have a map with strings, I want to transform it to a list of strings with ” ” as a key value separator. Is it possible using google collections?
Code example that I want to do using google collections:
public static List<String> addLstOfSetEnvVariables(Map<String, String> env)
{
ArrayList<String> result = Lists.newArrayList();
for (Entry<String, String> entry : env.entrySet())
{
result.add(entry.getKey() + " " + entry.getValue());
}
return result;
}
Here you go:
Update: optimized code. Using a Joiner constant should be much faster than String.concat()
These days, I would of course do this with Java 8 streams. No external lib needed.