Is it better practice to use String.format over string Concatenation in Java?

Is there a perceptible difference between using String.format and String concatenation in Java?

I tend to use String.format but occasionally will slip and use a concatenation. I was wondering if one was better than the other.

The way I see it, String.format gives you more power in “formatting” the string; and concatenation means you don’t have to worry about accidentally putting in an extra %s or missing one out.

String.format is also shorter.

Which one is more readable depends on how your head works.

15 Answers
15

Leave a Comment