Generating Messages approaches

adrhc :

At https://docs.oracle.com/javase/tutorial/i18n/text/usage.html I found this:

// recommended
System.out.printf("Character %c is invalid.%n", codePoint);

// not recommended
System.out.println("Character " + String.valueOf(char) + " is invalid.");

Why is one recommend and why the other is not?

UPDATE

The arguments provided by the documentation have not much meaning for me excepting the localization one:

This following approach is simple and avoids concatenation, which makes the text more difficult to localize as not all languages insert numeric values into a string in the same order as English.

Ashish :
System.out.printf("Character %c is invalid.%n", codePoint); //Recommended

The above approach is recommended because of localization of string is easier in this way. With respect to performance, this approach is not recommended as answered by @oleg.cherednik. This is already answered (more details available here) Is it better practice to use String.format over string Concatenation in Java?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326257&siteId=1