Close

Java String Formatting - How to format characters using String#printf()?

Java String Formatting Java 

This example shows how to format character with String#printf()

The format specifiers %c or %C is used for this purpose.

The result is unicode character. %C is to format a char in capital letter

package com.logicbig.example.string;

public class StringPrintfChar {

public static void main(String[] args) {
System.out.printf("%c%n", 'f');
System.out.printf("%C%n", 'f');
System.out.printf("%c%n", 100);
System.out.printf("%c%n", 178);
System.out.printf("%c%n", null);
}
}

Output

f
F
d
²
null




See Also