How to format strings ?
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); } }
The above code sample will produce the following result.
2.718282 2,7183
Advertisement