MessageFormat hashCode Example
MessageFormat class hashCode example. This example shows you how to use hashCode method.
MessageFormat class hashCode example. public int hashCode() Generates a hash code for the message format object.
Here is the code
/*
* @ # HashCode.java
* A class repersenting use to hashCode method
* of MessageFormat class in java.text package
* version 19 June 2008
* author Rose India
*/
import java.text.*;
public class HashCode {
public static void main(String[] args) {
// Create a pattern for our MessageFormat object to use.
String pattern = "I bought {0,number,#} " +
"apples for {1,number,currency} " +
"on {2,date,dd-MMM-yyyy}.";
// Create a MessageFormat object and apply the pattern
// to it.
MessageFormat mFmt = new MessageFormat(pattern);
Object[] values = null;
try {
values = mFmt.parse(
"I bought 20 apples for $4.18 on 11-Nov-2007.");
} catch (ParseException ex) {
System.out.println(ex.toString());
}
// Print out the pattern being used for formatting
// and the formatted output.
System.out.println(mFmt.format(values));
System.out.println("Hashcode " + mFmt.hashCode());
}
} |
Output
I bought {0} apples for {1} on {2}.
Hashcode -1027388079 |
|