java.text.CollationElementIterator類的setOffset()方法用於將迭代器的光標設置為作為參數傳遞的特定索引。
用法:
public void setOffset(int newOffset)
參數:此方法采用整數值newOffset,此時必須設置光標。
返回值:此方法無返回值。
下麵是說明setOffset()方法的示例:
範例1:
// Java program to demonstrate
// setOffset() method
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
// creating and intiallizing testString
String test = "Code Geeks 123";
// creating and intiallizing
// RuleBasedCollator object
RuleBasedCollator rbc
= (RuleBasedCollator)(Collator.getInstance());
// creating and intiallizing
// CollationElementIterator
CollationElementIterator cel
= rbc.getCollationElementIterator(test);
// setting offset to index 4
// using setOffset() method
cel.setOffset(4);
// display the result
System.out.println("current offset is "
+ cel.getOffset());
}
}
輸出:
current offset is 4
範例2:
// Java program to demonstrate
// setOffset() method
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
// creating and intiallizing testString
String test = "GeeksForGeeks";
// creating and intiallizing
// RuleBasedCollator object
RuleBasedCollator rbc
= (RuleBasedCollator)(Collator.getInstance());
// creating and intiallizing
// CollationElementIterator
CollationElementIterator cel
= rbc.getCollationElementIterator(test);
// after call of setOffset() method
// all next() method will become redundent
cel.next();
cel.next();
cel.next();
cel.next();
// setting cursor of iterator to index 0
// using setOffset() method
cel.setOffset(0);
// display the result
System.out.println("current offset is "
+ cel.getOffset());
}
}
輸出:
current offset is 0
參考: https://docs.oracle.com/javase/9/docs/api/java/text/CollationElementIterator.html#setOffset-int-
相關用法
- Java CollationElementIterator next()用法及代碼示例
- Java CollationElementIterator tertiaryOrder()用法及代碼示例
- Java CollationElementIterator previous()用法及代碼示例
- Java CollationElementIterator getOffset()用法及代碼示例
- Java CollationElementIterator reset()用法及代碼示例
- Java CollationElementIterator primaryOrder()用法及代碼示例
- Java CollationElementIterator getMaxExpansion()用法及代碼示例
- Java CollationElementIterator secondaryOrder()用法及代碼示例
- Java CollationElementIterator setText(String)用法及代碼示例
- Java CollationElementIterator setText(CharacterIterator)用法及代碼示例
- Java Java.util.Collections.disjoint()用法及代碼示例
- Java Java lang.Long.byteValue()用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java lang.Long.builtcount()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 CollationElementIterator setOffset() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。