CollationElementIterator setOffset() method in Java with Examples
The setOffset() method of java.text.CollationElementIterator class is used to set the cursor of the iterator to the particular index passed as parameter.
Syntax:
public void setOffset(int newOffset)
Parameter: This method takes an integer value newOffset at which point the cursor has to be set.
Return Value: This method has nothing to return.
Below are the examples to illustrate the setOffset() method:
Example 1:
Java
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 );
System.out.println( "current offset is "
+ cel.getOffset());
}
}
|
Output:
current offset is 4
Example 2:
Java
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
String test = "GeeksForGeeks" ;
RuleBasedCollator rbc
= (RuleBasedCollator)(Collator.getInstance());
CollationElementIterator cel
= rbc.getCollationElementIterator(test);
cel.next();
cel.next();
cel.next();
cel.next();
cel.setOffset( 0 );
System.out.println( "current offset is "
+ cel.getOffset());
}
}
|
Output:
current offset is 0
Reference: https://docs.oracle.com/javase/9/docs/api/java/text/CollationElementIterator.html#setOffset-int-
Last Updated :
05 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...