Easy Tutorial
❮ Java Arraylist Replaceall Java Map Interface ❯

Java Example - String Formatting

Java Examples

The following example demonstrates formatting strings using the format() method and specifying a locale for formatting:

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 locale as China (CHINA)
    }
}

The output of the above code example is:

2.718282
2.7183

Java Examples

❮ Java Arraylist Replaceall Java Map Interface ❯