Ad
  • Custom User Avatar

    I disagree, it's only false the first time, but it needs to be checked for each letter. Not needed, since we can add the "-" for each loop, and just remove the last char from the StringBuilder. Check my solution.

  • Custom User Avatar

    Check it again: it's only false the first time. It's true for the rest of the loop.

    While it's possible in Java 7 to resolve this without that if statement, it requires manually creating the head and tail, or doing weird things with the indices, or other things that reduce the overall readability of the code. This reduction in readibility is usually not worth the elimination of a single if statement.

    Anymore, the real solution would be to turn the char array into a stream, zip the index to it, process each element in the stream, then join the whole thing together on the dash. Keep that in mind bro.

    Such as here.

  • Custom User Avatar

    Please, use spoiler flag next time.