Friday, October 24, 2025
HomeLanguagesJavaBreakIterator isBoundary() method in Java with Examples

BreakIterator isBoundary() method in Java with Examples

The isBoundary() method of java.text.BreakIterator class is used to check if the passed offset is boundary or not.

Syntax:

public boolean isBoundary(int offset)

Parameter: This method takes offset as a parameter for checking if it is a boundary or not.

Return Value: This method provides true if the passed offset is boundary otherwise false.

Below are the examples to illustrate the isBoundary() method:

Example 1:




// Java program to demonstrate isBoundary() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing BreakIterator
        BreakIterator wb
            = BreakIterator.getWordInstance();
  
        // setting text for BreakIterator
        wb.setText("Code  Geeks");
  
        // checking for the boundary
        // by using isBoundary() method
        boolean status = wb.isBoundary(0);
  
        // display the result
        if (status)
            System.out.println("offset is a boundary");
        else
            System.out.println("offset is not a boundary");
    }
}


Output:

offset is a boundary

Example 2:




// Java program to demonstrate isBoundary() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing BreakIterator
        BreakIterator wb
            = BreakIterator.getWordInstance();
  
        // setting text for BreakIterator
        wb.setText("Code  Geeks");
  
        // checking for the boundary
        // by using isBoundary() method
        boolean status = wb.isBoundary(2);
  
        // display the result
        if (status)
            System.out.println("offset is a boundary");
        else
            System.out.println("offset is not a boundary");
    }
}


Output:

offset is not a boundary

Reference: https://docs.oracle.com/javase/9/docs/api/java/text/BreakIterator.html#isBoundary-int-

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS