The preceding() method of java.text.BreakIterator class is used to get the index of the character of the last boundary preceding the boundary of specified character offset. It provides the offset of the first character of boundary which follows or precedes the current boundary pointed by BreakIterator.
public int preceding(int offset)
Parameter: it takes offset of the character for which the previous boundary has to be found.
Return Value: This method provides the index of boundary which precedes the specified character offset.
Exception: This method throws IllegalArgumentException if the specified index is less than the first text boundary or greater than the last text boundary.
Below are the examples to illustrate the preceding() method:
current position before calling preceding() : 11 current position after calling 1st preceding() : 4 current position after calling 2nd preceding() : 6
current position before calling preceding() : 11 current position after calling 1st preceding() : 4 offset is less than the first boundary Exception thrown : java.lang.IllegalArgumentException: offset out of bounds
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.