Thursday, January 30, 2025
HomeProgrammingJava String format()

Java String format()

In Java, the String.format() method allows you to create formatted strings by embedding values into placeholders. It takes a format string and arguments, returning a new formatted string. The format string contains placeholders, represented by % symbols, which are replaced by the provided values in a specified format.

See also  How Does The 'Access-Control-Allow-Origin' Header Work?

For example:

java
String result = String.format("Hello, %s! Your balance is $%.2f.", "John", 1234.56);
System.out.println(result);

This will output: Hello, John! Your balance is $1234.56.

Common format specifiers include %s for strings, %d for integers, and %.2f for floating-point numbers.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x