I'd choose whichever makes the most sense to the structure of your program and not worry about which would be marginally more efficient than the other. See Jamie Robertson's reply to this topic. Pretty much sums it up. hth, bear [ October 29, 2002: Message edited by: Bear Bibeault ]
Originally posted by Graeme Brown: The performance differences, if any, are insignificant and will vary between versions of compiler and JVM. Think more about whether your code will be easier to read, understand, and maintain.
If I understand your question correctly, you would like to know which is more efficient:
I think the answer is probably the first way. It creates 3n String objects, and 3 String objects. (assuming all the elements are populated). The second way still has 3n String objects (to be populated). It also has 1 String object, and n String objects. The first way creates 3n + 3 objects. The second way creates 4n + 1 objects. I may not be counting one more for the String.class, not sure about that one. The overhead is probably not significant. We probably spent more time reading these messages than billions of iterations of your program will save in CPU time. So like Graeme Brown said, I would code it whichever way was easier to understand and adapt to change.