Ad
  • Custom User Avatar

    I think that the array list version is easier to read and in general a collection is going to be easier to work with in Java.

    The requirements don't mention that speed or memory are limited, so I didn't try to optimize my code for that. I think that in general best practices would say write the most readable and resuable code and if performance becomes an issue use a tool (profiler) to identify slow points (since the optimizer might actually correct something you assume is a problem).

  • Custom User Avatar

    You spend too much processing power creating an ArrayList to only convert it to an array. Why not declare the array?

  • Custom User Avatar

    Yes, since the string isn't being built in a loop, it is equivilent to using string concatenation. I prefer to use the string builder (and think it is as easy to read).

  • Custom User Avatar

    This is completely redundant, since simple string concatenation is compiled by java to the exact same code as you provided, while leaving source much more readable.