FieldPosition setBeginIndex Example
FieldPosition class setBeginIndex example. This example shows you how to use setBeginIndex method.
FieldPosition class setBeginIndex example. public void setBeginIndex(int) Sets the begin index. For use by subclasses of Format.
Here is the code
/*
* @ # SetBeginIndex.java
* A class repersenting use to SetBeginIndex method
* of FieldPosition class in java.text package
* version 17 June 2008
* author Rose India
*/
import java.text.*;
import java.math.*;
public class SetBeginIndex {
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);
BigDecimal bd1 = new BigDecimal(22.222001D);
buffer = numForm.format(bd1, buffer, pos);
pos.setBeginIndex(5);
pos.setEndIndex(10);
System.out.println("buffer = " + buffer);
System.out.println("INTEGER portion is at: " + pos.getBeginIndex() +
", " + pos.getEndIndex());
}
} |
Output
buffer = 22.222
INTEGER portion is at: 5, 10 |
|