FieldPosition hashCode Example
FieldPosition class hashCode example. This example shows you how to use hashCode method.
FieldPosition class hashCode example. public int hashCode() Returns a hash code for this FieldPosition.
Here is the code
/*
* @ # HashCode.java
* A class repersenting use to HashCode method
* of FieldPosition class in java.text package
* version 17 June 2008
* author Rose India
*/
import java.text.*;
import java.math.*;
public class HashCode {
public static void main(String[] args) {
// Get a default NumberFormat instance.
NumberFormat numForm = NumberFormat.getInstance();
// Format some decimals using the pattern supplied above.
StringBuffer buffer = new StringBuffer(24);
FieldPosition pos = new FieldPosition(NumberFormat.INTEGER_FIELD);
System.out.println("Hash code "+pos.hashCode());
BigDecimal bd1 = new BigDecimal(22.222001D);
buffer = numForm.format(bd1, buffer, pos);
System.out.println("buffer = " + buffer);
System.out.println("INTEGER portion is at: " + pos.getBeginIndex() +
", " + pos.getEndIndex());
System.out.println("Hash code "+pos.hashCode());
}
} |
Output
Hash code 0
buffer = 22.222
INTEGER portion is at: 0, 2
Hash code 2 |
|