Thursday, 29 August 2013

Is there any easy way within Java to prefix one string onto multiple other strings?

Is there any easy way within Java to prefix one string onto multiple other
strings?

Does anybody know if there is any easy way within Java to prefix one
string onto multiple other strings?
For example, if I have the following snippet of Java code ;
String includeDir = "/usr/local/boost-1.52.0/include";
ArrayList<String> filenamesRelative = new ArrayList<String>(),
filenamesAbsolute = new ArrayList<String>();
filenamesRelative.add("/boost/aligned_storage.hpp");
filenamesRelative.add("/boost/any.hpp");
I would like to be able to prefix the value of the variable 'includeDir',
i.e. "/usr/local/boost-1.52.0/include", onto the front of each value in
the ArrayList filenamesRelative.
Ideally, I would like to be able to do something like the following ;
filenameAbsolute = filenamesRelative.prefixAll(includeDir);
I don't necessarily have to use ArrayLists in the solution; I have just
used them above for illustrative purposes.
From memory, you can do something like this rather easily in C++ using the
STL, however my current working knowledge of Java isn't all that good
unfortunately :(
Thanks in advance for any assistance.

No comments:

Post a Comment