Reputation: 1167
String template = "%s and '%'";
String result = String.format(template, "my string");
System.out.println(result);
Expected:
my string and '%'
But result is:
java.util.UnknownFormatConversionException: Conversion = '''
Why? How to correctly declared the sequence '%'
so that it's ignored by String.format()
?
Upvotes: 32
Views: 17574
Reputation: 159754
%
is already used by format specifiers so it requires an additional %
to display that character:
String template = "%s and '%%'";
Upvotes: 74