Java中的 StringCharacterIterator previous() 方法及示例
Java中Java .text.StringCharacterIterator类的previous()方法用于获取该StringCharacterIterator要读取的前一个字符。此方法将此迭代器向后递减一个索引并返回前一个字符。
句法:
public char previous()
参数:此方法不接受任何参数。
返回值:此方法返回此 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");
stringCharacterIterator.next();
System.out.println("Current character: "
+ stringCharacterIterator
.current());
System.out.println("Previous character: "
+ stringCharacterIterator
.previous());
}
}
输出:
Current character: e
Previous character: G
参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/StringCharacterIterator.html#previous–