CollationElementIterator getOffset() method in Java with Examples
Last Updated :
03 Jan, 2020
The getOffset() method of java.text.CollationElementIterator class is used to get the index of item present at collator currently pointed by CollationElementIterator.
Syntax:
public int getOffset()
Parameter: This method does not accept any parameter.
Return Value: This method returns the offset of element currently pointed by iterator.
Below are the examples to illustrate the getOffset() method:
Example 1:
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
String test = "Code Geeks 123" ;
RuleBasedCollator rbc
= (RuleBasedCollator)(Collator.getInstance());
CollationElementIterator cel
= rbc.getCollationElementIterator(test);
cel.setOffset( 4 );
int value = cel.getOffset();
System.out.println( "current offset is "
+ value);
}
}
|
Output:
current offset is 4
Example 2:
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
String test = "Code Geeks 123" ;
RuleBasedCollator rbc
= (RuleBasedCollator)(Collator.getInstance());
CollationElementIterator cel
= rbc.getCollationElementIterator(test);
cel.setOffset( 4 );
cel.next();
int value = cel.getOffset();
System.out.println( "current offset is "
+ value);
}
}
|
Output:
current offset is 5
Reference: https://docs.oracle.com/javase/9/docs/api/java/text/CollationElementIterator.html#getOffset–
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...