GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.tutorialspoint.com — Java Formatter Class
Selected Reading
Java Formatter ClassIntroductionThe Java Formatter class provides support for layout justification and alignment, common formats for numeric, string, and date/time data, and locale-specific output.Following are the important points about Formatter −
Class declarationFollowing is the declaration for java.util.Formatter class − public final class Formatter extends Object implements Closeable, Flushable Class constructors
Class methods
Methods inheritedThis class inherits methods from the following classes −
Formatting a String using US Locale ExampleThe following example shows the usage of Java Formatter format(String, Object) method to format a string using a formatter. We've created a formatter object with a StringBuffer and a locale. Formatter is used to print a string using the format() method. package com.tutorialspoint;
import java.util.Formatter;
import java.util.Locale;
public class FormatterDemo {
public static void main(String[] args) {
// create a new formatter
StringBuffer buffer = new StringBuffer();
Formatter formatter = new Formatter(buffer, Locale.US);
// format a new string
String name = "World";
formatter.format("Hello %s !", name);
// print the formatted string
System.out.println(formatter);
formatter.close();
}
}
OutputLet us compile and run the above program, this will produce the following result − Hello World ! Advertisements
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |