Java中的 StringCharacterIterator getIndex() 方法及示例
Java中Java .text.StringCharacterIterator类的getIndex()方法用于获取该StringCharacterIterator要读取的当前索引。此方法返回该索引号。
句法:
public int getIndex()
参数:此方法不接受任何参数。
返回值:此方法返回此 StringCharacterIterator 要读取的索引号。
异常:此方法不抛出任何异常。
程序:
// Java program to demonstrate
// the above method
import java.text.*;
import java.util.*;
public class StringCharacterIteratorDemo {
public static void main(String[] args)
{
StringCharacterIterator stringCharacterIterator
= new StringCharacterIterator(
"GeeksForGeeks");
System.out.println("Current character: "
+ stringCharacterIterator
.current());
System.out.println("Current Index: "
+ stringCharacterIterator
.getIndex());
}
}
输出:
Current character: G
Current Index: 0
参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/StringCharacterIterator.html#getIndex–