Java 中 StringCharacterIterator previous()方法,示例

原文:https://www . geeksforgeeks . org/stringcharacterterator-previous-method-in-Java-with-examples/

前朝()。Java 中的 stringcharacterTerter 类用来获取这个 stringcharacterTerter 要读取的前一个字符。这个方法将迭代器向后递减一个索引,并返回前一个字符。

语法:

public char previous()

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

返回值:该方法返回该字符串特征符要读取的前一个字符。

异常:这个方法不抛出任何异常。

程序:

// 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/stringcharactersterator . html # previous–