Java Examples - String Formatting
The following example demonstrates how to format strings using the format() method, and you can also specify a locale to format:
StringFormat.java file
import java.util.*;
public class StringFormat {
public static void main(String[] args){
double e = Math.E;
System.out.format("%f%n", e);
System.out.format(Locale.CHINA , "%-10.4f%n%n", e); //Specify the locale as China (CHINA)
}
}
The output of the above code example is:
2.718282 2.7183Other Extensions
Java Examples