MessageFormat getLocale Example
MessageFormat class getLocale example. This example shows you how to use getLocale method.
MessageFormat class getLocale example. public Locale getLocale() Gets the locale that's used when creating or comparing subformats.
Here is the code
/*
* @ # GetLocale.java
* A class repersenting use to getLocale method
* of MessageFormat class in java.text package
* version 19 June 2008
* author Rose India
*/
import java.text.*;
public class GetLocale {
public static void main(String[] args) {
String pattern = "I bought {0,number,#} " +
"apples for {1,number,currency} " +
"on {2,date,dd-MMM-yyyy}.";
java.text.Format[] formats = {new DecimalFormat("#"),
NumberFormat.getCurrencyInstance(),
new SimpleDateFormat("MMM/dd/yyyy")
};
Object[] values = {new Integer(15), new Double(17.53),
new java.util.Date("14-Jul-2008")
};
MessageFormat mFmt = new MessageFormat(pattern);
mFmt.setFormats(formats);
mFmt.applyPattern(pattern);
System.out.println(mFmt.format(pattern, values));
System.out.println("Locale " + mFmt.getLocale());
}
} |
Output
I bought 15 apples for Rs.17.53 on 14-Jul-2008.
Locale en_IN |
|