How do I, without using any loop, modify the values in a collection to get a new collection with the modified values?
For example, I'm having a Collection<String>
and want to surround all Strings by parentheses.
With a loop I would do this:
Iterable<String> collection = getCollection();
ArrayList<String> newCollection = new ArrayList<String>();
for(String str : collection)
newCollection.add("(" + str + ")");
There has to be a more elegant solution.
EDIT: Use of third party utilities is allowed :)