Java中java.text.CharacterIterator接口的next()方法用於獲取該CharacterIterator讀取的下一個字符。此方法將該迭代器遞減至一個索引,然後返回下一個字符。
用法:
public char next()
參數:此方法不接受任何參數。
返回值:此方法返回此CharacterIterator讀取的下一個字符。
異常:此方法不引發任何異常。
程序:
// Java program to demonstrate
// the above method
import java.text.*;
import java.util.*;
public class CharacterIteratorDemo {
public static void main(String[] args)
{
CharacterIterator characterIterator
= new StringCharacterIterator(
"GeeksForGeeks");
System.out.println("Current character: "
+ characterIterator
.current());
System.out.println("Next character: "
+ characterIterator
.next());
}
}
輸出:
Current character: G Next character: e
參考: https://docs.oracle.com/javase/9/docs/api/java/text/CharacterIterator.html#next–
相關用法
- Java CharacterIterator first()用法及代碼示例
- Java CharacterIterator last()用法及代碼示例
- Java CharacterIterator setIndex()用法及代碼示例
- Java CharacterIterator current()用法及代碼示例
- Java CharacterIterator getIndex()用法及代碼示例
- Java CharacterIterator getBeginIndex()用法及代碼示例
- Java CharacterIterator clone()用法及代碼示例
- Java CharacterIterator previous()用法及代碼示例
- Java CharacterIterator getEndIndex()用法及代碼示例
- Java BreakIterator setText(CharacterIterator)用法及代碼示例
- Java RuleBasedCollator getCollationElementIterator(CharacterIterator)用法及代碼示例
- Java CollationElementIterator setText(CharacterIterator)用法及代碼示例
- Java Java lang.Long.lowestOneBit()用法及代碼示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代碼示例
- Java Java.util.Collections.disjoint()用法及代碼示例
注:本文由純淨天空篩選整理自ShubhamMaurya3大神的英文原創作品 CharacterIterator next() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。