BreakIterator setText(CharacterIterator) method in Java with Examples Last Updated : 02 Jun, 2021 Comments Improve Suggest changes Like Article Like Report The setText(CharacterIterator) method of java.text.BreakIterator class is used to set the new text into the BreakIterator using CharacterIterator object. Syntax: public abstract void setText(CharacterIterator newText) Parameter: This method takes CharacterIterator object as a parameter which contains the new text to be set. Return Value: This method returns nothing. Below are the examples to illustrate the setText() method: Example 1: Java // Java program to demonstrate setText() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { // creating and initializing CharacterIterator object CharacterIterator word = new StringCharacterIterator("GeeksForGEEks"); // creating and initializing BreakIterator BreakIterator wb = BreakIterator.getWordInstance(); // setting text for BreakIterator // using setText() method wb.setText(word); // getting the text being scanned by // using getText() method StringCharacterIterator text = (StringCharacterIterator)wb.getText(); // display the result System.out.print("Retrieved text is : " + text.first()); for (int i = text.getBeginIndex() - 1; i < text.getEndIndex() - 2; i++) System.out.print(text.next()); } } OutputRetrieved text is : GeeksForGEEks Example 2: Java // Java program to demonstrate setText() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { // creating and initializing CharacterIterator object CharacterIterator word = new StringCharacterIterator("TextView"); // creating and initializing BreakIterator BreakIterator wb = BreakIterator.getWordInstance(); // setting text for BreakIterator // using setText() method wb.setText(word); // getting the text being scanned by // using getText() method StringCharacterIterator text = (StringCharacterIterator)wb.getText(); // display the result System.out.print("Retrieved text is : " + text.first()); for (int i = text.getBeginIndex() - 1; i < text.getEndIndex() - 2; i++) System.out.print(text.next()); } } OutputRetrieved text is : TextView Reference: https://docs.oracle.com/javase/9/docs/api/java/text/BreakIterator.html#setText-java.text.CharacterIterator- Comment More infoAdvertise with us Next Article BreakIterator setText(CharacterIterator) method in Java with Examples rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-text package Java-BreakIterator Practice Tags : Java Similar Reads CharacterIterator setIndex() method in Java with Examples The setIndex() method of java.text.CharacterIterator interface in Java is used to set the current index that is to be read by this CharacterIterator. This method takes the index to be set as a parameter and sets the index of this CharacterIterator at that index and then it returns that character. Sy 1 min read CharacterIterator next() method in Java with Examples The next() method of java.text.CharacterIterator interface in Java is used to get the next character that is to be read by this CharacterIterator. This method decrements this iterator to one index forward and returns that next character. Syntax: public char next() Parameter: This method do not accep 1 min read CollationElementIterator setText(CharacterIterator) method in Java with Example The setText() method of java.text.CollationElementIterator class is used to set the new source string for CollationElementIterator object to iterate. Syntax: public void setText(CharacterIterator source) Parameter: This method takes a new CharacterIterator object contains string value over which ite 3 min read BreakIterator current() method in Java with Examples The current() method of java.text.BreakIterator class is used to get the index of recent text boundary in the line of words. It provides the offset of the text which is currently pointed by the BreakIterator. Syntax: public abstract int current() Parameter: This method does not accept any parameter. 3 min read BreakIterator setText(String) method in Java with Examples The setText() method of java.text.BreakIterator class is used to set the new text into the BreakIterator.Syntax: public void setText(String newText) Parameter: This method takes text in the form of string as parameter.Return Value: This method returns nothing.Below are the examples to illustrate the 2 min read BreakIterator next() method in Java with Examples The next() method of java.text.BreakIterator class is used to get the index of the next boundary ahead of the current boundary(boundary retrieved by calling current() method). it provides the offset of the first character of boundary which follows the current boundary pointed by BreakIterator. Synta 2 min read CharacterIterator previous() method in Java with Examples The previous() method of java.text.CharacterIterator interface in Java is used to get the previous character that is to be read by this CharacterIterator. This method decrements this iterator to one index backwards and returns that previous character. Syntax: public char previous() Parameter: This m 1 min read CharacterIterator first() method in Java with Examples The first() method of java.text.CharacterIterator interface in Java is used to get the character at the beginning of this CharacterIterator. This method sets the position of the iterator to the first character, using getBeginIndex(), and then returns that character. Syntax: public char first() Param 1 min read CharacterIterator clone() method in Java with Examples The clone() method of java.text.CharacterIterator interface in Java is used to clone this CharacterIterator. It means that this method will create another instance of CharacterIterator with all the properties the same as this CharacterIterator and return it. Syntax: public Object clone() Parameter: 1 min read CharacterIterator last() method in Java with Examples The last() method of java.text.CharacterIterator interface in Java is used to get the character at the ending of this CharacterIterator. This method sets the position of the iterator to the last character, using getEndIndex(), and then returns that character. Syntax: public char last() Parameter: Th 1 min read Like