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–
相關用法
- Java CharacterIterator getIndex()用法及代碼示例
- Java StringCharacterIterator first()用法及代碼示例
- Java StringCharacterIterator next()用法及代碼示例
- Java StringCharacterIterator last()用法及代碼示例
- Java StringCharacterIterator hashCode()用法及代碼示例
- Java StringCharacterIterator clone()用法及代碼示例
- Java StringCharacterIterator getEndIndex()用法及代碼示例
- Java StringCharacterIterator setText()用法及代碼示例
- Java StringCharacterIterator setIndex()用法及代碼示例
- Java StringCharacterIterator equals()用法及代碼示例
- Java StringCharacterIterator current()用法及代碼示例
- Java StringCharacterIterator getBeginIndex()用法及代碼示例
- Java StringCharacterIterator previous()用法及代碼示例
- Java ParsePosition getIndex()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
注:本文由純淨天空篩選整理自ShubhamMaurya3大神的英文原創作品 StringCharacterIterator getIndex() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。