formartted string java 1

formartted string java

String str = String.format( "Hello \n World \n my name is %s and i'm %d years old" , "Paul", 27);  

Here is what the above code is Doing:
1. We’re using the String.format() method to create a string with placeholders.
2. We’re passing the string “Paul” and the number 27 as arguments to the String.format() method.
3. The String.format() method replaces the placeholders in the string with the arguments we passed to it.
4. The String.format() method returns the formatted string.
5. We’re assigning the formatted string to the str variable.

Similar Posts