📌  相关文章
📜  Java中的 CharacterIterator previous() 方法及示例

📅  最后修改于: 2022-05-13 01:55:40.668000             🧑  作者: Mango

Java中的 CharacterIterator previous() 方法及示例

Java中Java .text.CharacterIterator接口previous()方法用于获取该CharacterIterator要读取的前一个字符。此方法将此迭代器向后递减一个索引并返回前一个字符。

句法:

public char previous()

参数:此方法不接受任何参数。

返回值:此方法返回此 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");
  
        characterIterator.next();
  
        System.out.println("Current character: "
                           + characterIterator
                                 .current());
  
        System.out.println("Previous character: "
                           + characterIterator
                                 .previous());
    }
}
输出:
Current character: e
Previous character: G

参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/CharacterIterator.html#previous–