當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java BreakIterator isBoundary()用法及代碼示例


java.text.BreakIterator類的isBoundary()方法用於檢查傳遞的偏移量是否為邊界。

用法:

public boolean isBoundary(int offset)

參數:此方法將offset作為參數檢查其是否為邊界。


返回值:如果傳遞的偏移量是邊界,則此方法提供true,否則提供false。

下麵是說明isBoundary()方法的示例:

示例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"); 
    } 
}
輸出:
offset is a boundary

示例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"); 
    } 
}
輸出:
offset is not a boundary

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



相關用法


注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 BreakIterator isBoundary() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。