Bhagat Singh Rawat wrote:Its homework in terms of performance, I have 3 solutions: ...
There is really only one way to do this: go through all the values in the set and concatenate them together. All three of your solutions come down to the same, there will not be a major performance difference between them. I bet that if you look up the source code of the StringUtils method from Apache Commons, it will be very similar to your first solution.
Performance-wise, you're already doing the right thing in your own first solution in that you are using a StringBuilder to concatenate all the parts together, instead of using String objects and concatenating them with the + operator (that would make a lot of unnecessary temporary String objects and unnecessary copying of data).
By the way, this is not really a question about the
SCJP. I will move this topic to a more appropriate forum for you.