Java 中的 boolean regionMatches(int

首页 / Java入门教程 / Java 中的 boolean regionMatches(int

测试两个字符串区域是否相等。

boolean regionMatches - 语法

public boolean regionMatches(int toffset,
                             String other,
                             int ooffset,
                             int len)

这是参数的详细信息-

  • toffset    - 该字符串中子区域的起始偏移。

  • other      - 字符串参数。

  • ooffset   - 字符串参数中子区域的起始偏移。

  • len         - 要比较的字符数。

boolean regionMatches - 返回值

  • 如果此字符串的指定子区域与字符串参数的指定子区域匹配,则返回true;否则为fakse。匹配的精确性还是不区分大小写取决于ignoreCase参数。

boolean regionMatches - 示例

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str1=new String("Welcome to Learnfk.com");
      String Str2=new String("Learnfk");
      String Str3=new String("LEARNFK");

      System.out.print("返回值 :" );
      System.out.println(Str1.regionMatches(11, Str2, 0, 9));

      System.out.print("返回值 :" );
      System.out.println(Str1.regionMatches(11, Str3, 0, 9));
   }
}

这将产生以下输出-

返回值 :true
返回值 :false

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

React实战进阶45讲 -〔王沛〕

从0开始学大数据 -〔李智慧〕

设计模式之美 -〔王争〕

接口测试入门课 -〔陈磊〕

编译原理实战课 -〔宫文学〕

OAuth 2.0实战课 -〔王新栋〕

人人都用得上的写作课 -〔涵柏〕

Redis源码剖析与实战 -〔蒋德钧〕

AI大模型企业应用实战 -〔蔡超〕

好记忆不如烂笔头。留下您的足迹吧 :)