Latest web development tutorials

Java Examples - string formatting

Java Examples Java Examples

The following example demonstrates by format () method to format string, you can also specify the area to format ():

//StringFormat.java 文件

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.GERMANY, "%-10.4f%n%n", e);  //指定本地为德国(GERMANY)
   }
}

The output is the above code examples:

2.718282
2,7183

Java Examples Java Examples