Tutorials Point


  Java Basics Examples
  Java Tutorial
  Java Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Java Examples - String formatting


previous next AddThis Social Bookmark Button


Problem Description:

How to format strings ?

Solution:

Following example returns a formatted string value by using a specific locale, format and arguments in format() method

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);
   }
}

Result:

The above code sample will produce the following result.

2.718282
2,7183     


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names