Java中的 StringCharacterIterator clone() 方法及示例
Java中Java .text.StringCharacterIterator类的clone()方法就是用来克隆这个StringCharacterIterator的。这意味着此方法将创建另一个 StringCharacterIterator 实例,其所有属性与此 StringCharacterIterator 相同并返回它。
句法:
public Object clone()
参数:此方法不接受任何参数。
返回值:此方法返回一个Object ,它是此 StringCharacterIterator 的克隆。
异常:此方法不抛出任何异常。
程序:
// Java program to demonstrate
// the above method
import java.text.*;
import java.util.*;
public class StringCharacterIteratorDemo {
public static void main(String[] args)
{
String text = "GeeksForGeeks";
StringCharacterIterator
stringCharacterIterator
= new StringCharacterIterator(text);
System.out.println("Current StringCharacterIterator: "
+ stringCharacterIterator);
System.out.println("Cloned StringCharacterIterator: "
+ stringCharacterIterator.clone());
}
}
输出:
Current StringCharacterIterator:
java.text.StringCharacterIterator@c11e1b98
Cloned StringCharacterIterator:
java.text.StringCharacterIterator@c11e1b98
参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/StringCharacterIterator.html#clone–