[Java] 查找匹配字符串(StringBuffer ) →→→→→进入此内容的聊天室

来自 , 2020-06-14, 写在 Java, 查看 138 次.
URL http://www.code666.cn/view/c3992e9a
  1.         /**
  2.          * 查找匹配字符串
  3.          */
  4.         public static void testFindStr() {
  5.                 StringBuffer sb = new StringBuffer("This is a StringBuffer!");
  6.                 // indexOf返回子字符串在字符串中的最先出现的位置,如果不存在,返回负数。
  7.                 System.out.println("sb.indexOf(\"is\") = " + sb.indexOf("is"));
  8.                 // 可以给indexOf方法设置参数,指定匹配的起始位置
  9.                 System.out.println("sb.indexOf(\"is\", 4) = " + sb.indexOf("is", 4));
  10.                 // lastIndexOf返回子字符串在字符串中的最后出现的位置,如果不存在,返回负数。
  11.                 System.out.println("sb.lastIndexOf(\"is\") = " + sb.lastIndexOf("is"));
  12.                 // 可以给lastIndexOf方法设置参数,指定匹配的结束位置
  13.                 System.out.println("sb.lastIndexOf(\"is\", 1) = "
  14.                                 + sb.lastIndexOf("is", 1));
  15.         }

回复 "查找匹配字符串(StringBuffer )"

这儿你可以回复上面这条便签

captcha