Java Basics Examples
Java Tutorial
Java Useful Resources
Selected Reading
© 2013 TutorialsPoint.COM
|
Java Examples - String formatting
Advertisements
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.
Advertisements
|
|
|