# BreakIterator

public abstract class **BreakIterator** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [Cloneable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Cloneable.html) The `BreakIterator` class implements methods for finding
the location of boundaries in text. Instances of `BreakIterator`
maintain a current position and scan over text
returning the index of characters where boundaries occur.
Internally, `BreakIterator` scans text using a
`CharacterIterator`, and is thus able to scan text held
by any object implementing that protocol. A `StringCharacterIterator`
is used to scan `String` objects passed to `setText`.
The `CharacterIterator` object must not be modified after having been
passed to `setText`. If the text in the `CharacterIterator` object
is changed, the caller must reset `BreakIterator` by calling
`setText`.


You use the factory methods provided by this class to create
instances of various types of break iterators. In particular,
use `getWordInstance`, `getLineInstance`,
`getSentenceInstance`, and `getCharacterInstance`
to create `BreakIterator`s that perform
word, line, sentence, and character boundary analysis respectively.
A single `BreakIterator` can work only on one unit
(word, line, sentence, and so on). You must use a different iterator
for each unit boundary analysis you wish to perform.


Line boundary analysis determines where a text string can be
broken when line-wrapping. The mechanism correctly handles
punctuation and hyphenated words. Actual line breaking needs
to also consider the available line width and is handled by
higher-level software.


Sentence boundary analysis allows selection with correct interpretation
of periods within numbers and abbreviations, and trailing punctuation
marks such as quotation marks and parentheses.


Word boundary analysis is used by search and replace functions, as
well as within text editing applications that allow the user to
select words with a double click. Word selection provides correct
interpretation of punctuation marks within and following
words. Characters that are not part of a word, such as symbols
or punctuation marks, have word-breaks on both sides.


Character boundary analysis allows users to interact with characters
as they expect to, for example, when moving the cursor through a text
string. Character boundary analysis provides correct navigation
through character strings, regardless of how the character is stored.
The boundaries returned may be those of supplementary characters,
combining character sequences, or ligature clusters.
For example, an accented character might be stored as a base character
and a diacritical mark. What users consider to be a character can
differ between languages.


The `BreakIterator` instances returned by the factory methods
of this class are intended for use with natural languages only, not for
programming language text. It is however possible to define subclasses
that tokenize a programming language.


**Examples**:


Creating and using text boundaries:
>
> ```
>  public static void main(String args[]) {
>       if (args.length == 1) {
>           String stringToExamine = args[0];
>           //print each word in order
>           BreakIterator boundary = BreakIterator.getWordInstance();
>           boundary.setText(stringToExamine);
>           printEachForward(boundary, stringToExamine);
>           //print each sentence in reverse order
>           boundary = BreakIterator.getSentenceInstance(Locale.US);
>           boundary.setText(stringToExamine);
>           printEachBackward(boundary, stringToExamine);
>           printFirst(boundary, stringToExamine);
>           printLast(boundary, stringToExamine);
>       }
>  }
>  
> ```
Print each element in order:
>
> ```
>  public static void printEachForward(BreakIterator boundary, String source) {
>      int start = boundary.first();
>      for (int end = boundary.next();
>           end != BreakIterator.DONE;
>           start = end, end = boundary.next()) {
>           System.out.println(source.substring(start,end));
>      }
>  }
>  
> ```
Print each element in reverse order:
>
> ```
>  public static void printEachBackward(BreakIterator boundary, String source) {
>      int end = boundary.last();
>      for (int start = boundary.previous();
>           start != BreakIterator.DONE;
>           end = start, start = boundary.previous()) {
>          System.out.println(source.substring(start,end));
>      }
>  }
>  
> ```
Print first element:
>
> ```
>  public static void printFirst(BreakIterator boundary, String source) {
>      int start = boundary.first();
>      int end = boundary.next();
>      System.out.println(source.substring(start,end));
>  }
>  
> ```
Print last element:
>
> ```
>  public static void printLast(BreakIterator boundary, String source) {
>      int end = boundary.last();
>      int start = boundary.previous();
>      System.out.println(source.substring(start,end));
>  }
>  
> ```
Print the element at a specified position:
>
> ```
>  public static void printAt(BreakIterator boundary, int pos, String source) {
>      int end = boundary.following(pos);
>      int start = boundary.previous();
>      System.out.println(source.substring(start,end));
>  }
>  
> ```
Find the next word:
>
>     public static int nextWordStartAfter(int pos, String text) {
>          BreakIterator wb = BreakIterator.getWordInstance();
>          wb.setText(text);
>          int last = wb.following(pos);
>          int current = wb.next();
>          while (current != BreakIterator.DONE) {
>              for (int p = last; p < current; p++) {
>                  if (Character.isLetter(text.codePointAt(p)))
>                      return last;
>              }
>              last = current;
>              current = wb.next();
>          }
>          return BreakIterator.DONE;
>      }
>      
> (The iterator returned by BreakIterator.getWordInstance() is unique in that the break positions it returns don't represent both the start and end of the thing being iterated over. That is, a sentence-break iterator returns breaks that each represent the end of one sentence and the beginning of the next. With the word-break iterator, the characters between two boundaries might be a word, or they might be the punctuation or whitespace between two words. The above code uses a simple heuristic to determine which boundary is the beginning of a word: If the characters between this boundary and the next boundary include at least one letter (this can be an alphabetical letter, a CJK ideograph, a Hangul syllable, a Kana character, etc.), then the text between this boundary and the next is a word; otherwise, it's the material between words.)

<br />

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/text/CharacterIterator.html`

### Constant Summary

|---|---|---|
| int | [DONE](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#DONE) | DONE is returned by previous(), next(), next(int), preceding(int) and following(int) when either the first or last text boundary has been reached. |

### Protected Constructor Summary

|---|---|
|   | [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#BreakIterator())() Constructor. |

### Public Method Summary

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#clone())() Create a copy of this iterator |
| abstract int | [current](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#current())() Returns character index of the text boundary that was most recently returned by next(), next(int), previous(), first(), last(), following(int) or preceding(int). |
| abstract int | [first](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#first())() Returns the first boundary. |
| abstract int | [following](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#following(int))(int offset) Returns the first boundary following the specified character offset. |
| synchronized static [Locale\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Locale.html) | [getAvailableLocales](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#getAvailableLocales())() Returns an array of all locales for which the `get*Instance` methods of this class can return localized instances. |
| static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html) | [getCharacterInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#getCharacterInstance(java.util.Locale))([Locale](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Locale.html) locale) Returns a new `BreakIterator` instance for [character breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#character) for the given locale. |
| static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html) | [getCharacterInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#getCharacterInstance())() Returns a new `BreakIterator` instance for [character breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#character) for the {@linkplain Locale#getDefault() default locale}. |
| static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html) | [getLineInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#getLineInstance(java.util.Locale))([Locale](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Locale.html) locale) Returns a new `BreakIterator` instance for [line breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#line) for the given locale. |
| static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html) | [getLineInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#getLineInstance())() Returns a new `BreakIterator` instance for [line breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#line) for the {@linkplain Locale#getDefault() default locale}. |
| static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html) | [getSentenceInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#getSentenceInstance(java.util.Locale))([Locale](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Locale.html) locale) Returns a new `BreakIterator` instance for [sentence breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#sentence) for the given locale. |
| static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html) | [getSentenceInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#getSentenceInstance())() Returns a new `BreakIterator` instance for [sentence breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#sentence) for the {@linkplain Locale#getDefault() default locale}. |
| abstract [CharacterIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/CharacterIterator.html) | [getText](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#getText())() Get the text being scanned |
| static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html) | [getWordInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#getWordInstance())() Returns a new `BreakIterator` instance for [word breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#word) for the {@linkplain Locale#getDefault() default locale}. |
| static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html) | [getWordInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#getWordInstance(java.util.Locale))([Locale](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Locale.html) locale) Returns a new `BreakIterator` instance for [word breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#word) for the given locale. |
| boolean | [isBoundary](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#isBoundary(int))(int offset) Returns true if the specified character offset is a text boundary. |
| abstract int | [last](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#last())() Returns the last boundary. |
| abstract int | [next](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#next())() Returns the boundary following the current boundary. |
| abstract int | [next](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#next(int))(int n) Returns the nth boundary from the current boundary. |
| int | [preceding](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#preceding(int))(int offset) Returns the last boundary preceding the specified character offset. |
| abstract int | [previous](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#previous())() Returns the boundary preceding the current boundary. |
| void | [setText](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#setText(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) newText) Set a new text string to be scanned. |
| abstract void | [setText](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#setText(java.text.CharacterIterator))([CharacterIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/CharacterIterator.html) newText) Set a new text for scanning. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Constants

#### public static final int
**DONE**

DONE is returned by previous(), next(), next(int), preceding(int)
and following(int) when either the first or last text boundary has been
reached.
Constant Value: -1

## Protected Constructors

#### protected
**BreakIterator**
()

Constructor. BreakIterator is stateless and has no default behavior.

## Public Methods

#### public [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)
**clone**
()

Create a copy of this iterator

##### Returns

- A copy of this

#### public abstract int
**current**
()

Returns character index of the text boundary that was most
recently returned by next(), next(int), previous(), first(), last(),
following(int) or preceding(int). If any of these methods returns
`BreakIterator.DONE` because either first or last text boundary
has been reached, it returns the first or last text boundary depending on
which one is reached.

##### Returns

- The text boundary returned from the above methods, first or last text boundary.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#next()`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#next(int)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#previous()`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#first()`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#last()`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#following(int)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#preceding(int)`

#### public abstract int
**first**
()

Returns the first boundary. The iterator's current position is set
to the first text boundary.

##### Returns

- The character index of the first text boundary.

#### public abstract int
**following**
(int offset)

Returns the first boundary following the specified character offset. If the
specified offset equals to the last text boundary, it returns
`BreakIterator.DONE` and the iterator's current position is unchanged.
Otherwise, the iterator's current position is set to the returned boundary.
The value returned is always greater than the offset or the value
`BreakIterator.DONE`.

##### Parameters

| offset | the character offset to begin scanning. |
|---|---|

##### Returns

- The first boundary after the specified offset or `BreakIterator.DONE` if the last text boundary is passed in as the offset.

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the specified offset is less than the first text boundary or greater than the last text boundary. |
|---|---|

#### public static synchronized [Locale\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Locale.html)
**getAvailableLocales**
()

Returns an array of all locales for which the
`get*Instance` methods of this class can return
localized instances.

##### Returns

- An array of locales for which localized `BreakIterator` instances are available.

#### public static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html)
**getCharacterInstance**
([Locale](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Locale.html) locale)

Returns a new `BreakIterator` instance
for [character breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#character)
for the given locale.

##### Parameters

| locale | the desired locale |
|---|---|

##### Returns

- A break iterator for character breaks

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `locale` is null |
|---|---|

#### public static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html)
**getCharacterInstance**
()

Returns a new `BreakIterator` instance
for [character breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#character)
for the {@linkplain Locale#getDefault() default locale}.

##### Returns

- A break iterator for character breaks

#### public static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html)
**getLineInstance**
([Locale](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Locale.html) locale)

Returns a new `BreakIterator` instance
for [line breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#line)
for the given locale.

##### Parameters

| locale | the desired locale |
|---|---|

##### Returns

- A break iterator for line breaks

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `locale` is null |
|---|---|

#### public static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html)
**getLineInstance**
()

Returns a new `BreakIterator` instance
for [line breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#line)
for the {@linkplain Locale#getDefault() default locale}.

##### Returns

- A break iterator for line breaks

#### public static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html)
**getSentenceInstance**
([Locale](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Locale.html) locale)

Returns a new `BreakIterator` instance
for [sentence breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#sentence)
for the given locale.

##### Parameters

| locale | the desired locale |
|---|---|

##### Returns

- A break iterator for sentence breaks

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `locale` is null |
|---|---|

#### public static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html)
**getSentenceInstance**
()

Returns a new `BreakIterator` instance
for [sentence breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#sentence)
for the {@linkplain Locale#getDefault() default locale}.

##### Returns

- A break iterator for sentence breaks

#### public abstract [CharacterIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/CharacterIterator.html)
**getText**
()

Get the text being scanned

##### Returns

- the text being scanned

#### public static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html)
**getWordInstance**
()

Returns a new `BreakIterator` instance
for [word breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#word)
for the {@linkplain Locale#getDefault() default locale}.

##### Returns

- A break iterator for word breaks

#### public static [BreakIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html)
**getWordInstance**
([Locale](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Locale.html) locale)

Returns a new `BreakIterator` instance
for [word breaks](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator#word)
for the given locale.

##### Parameters

| locale | the desired locale |
|---|---|

##### Returns

- A break iterator for word breaks

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `locale` is null |
|---|---|

#### public boolean
**isBoundary**
(int offset)

Returns true if the specified character offset is a text boundary.

##### Parameters

| offset | the character offset to check. |
|---|---|

##### Returns

- `true` if "offset" is a boundary position, `false` otherwise.

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the specified offset is less than the first text boundary or greater than the last text boundary. |
|---|---|

#### public abstract int
**last**
()

Returns the last boundary. The iterator's current position is set
to the last text boundary.

##### Returns

- The character index of the last text boundary.

#### public abstract int
**next**
()

Returns the boundary following the current boundary. If the current boundary
is the last text boundary, it returns `BreakIterator.DONE` and
the iterator's current position is unchanged. Otherwise, the iterator's
current position is set to the boundary following the current boundary.

##### Returns

- The character index of the next text boundary or `BreakIterator.DONE` if the current boundary is the last text boundary. Equivalent to next(1).

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/text/BreakIterator.html#next(int)`

#### public abstract int
**next**
(int n)

Returns the nth boundary from the current boundary. If either
the first or last text boundary has been reached, it returns
`BreakIterator.DONE` and the current position is set to either
the first or last text boundary depending on which one is reached. Otherwise,
the iterator's current position is set to the new boundary.
For example, if the iterator's current position is the mth text boundary
and three more boundaries exist from the current boundary to the last text
boundary, the next(2) call will return m + 2. The new text position is set
to the (m + 2)th text boundary. A next(4) call would return
`BreakIterator.DONE` and the last text boundary would become the
new text position.

##### Parameters

| n | which boundary to return. A value of 0 does nothing. Negative values move to previous boundaries and positive values move to later boundaries. |
|---|---|

##### Returns

- The character index of the nth boundary from the current position or `BreakIterator.DONE` if either first or last text boundary has been reached.

#### public int
**preceding**
(int offset)

Returns the last boundary preceding the specified character offset. If the
specified offset equals to the first text boundary, it returns
`BreakIterator.DONE` and the iterator's current position is unchanged.
Otherwise, the iterator's current position is set to the returned boundary.
The value returned is always less than the offset or the value
`BreakIterator.DONE`.

##### Parameters

| offset | the character offset to begin scanning. |
|---|---|

##### Returns

- The last boundary before the specified offset or `BreakIterator.DONE` if the first text boundary is passed in as the offset.

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the specified offset is less than the first text boundary or greater than the last text boundary. |
|---|---|

#### public abstract int
**previous**
()

Returns the boundary preceding the current boundary. If the current boundary
is the first text boundary, it returns `BreakIterator.DONE` and
the iterator's current position is unchanged. Otherwise, the iterator's
current position is set to the boundary preceding the current boundary.

##### Returns

- The character index of the previous text boundary or `BreakIterator.DONE` if the current boundary is the first text boundary.

#### public void
**setText**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) newText)

Set a new text string to be scanned. The current scan
position is reset to first().

##### Parameters

| newText | new text to scan. |
|---|---|

#### public abstract void
**setText**
([CharacterIterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/text/CharacterIterator.html) newText)

Set a new text for scanning. The current scan
position is reset to first().

##### Parameters

| newText | new text to scan. |
|---|---|