Java字串包含示例。


String 類中的 contains() 方法僅當字串包含指定的 char 值序列時返回 true。

示例

即時演示

import java.lang.*;
public class StringDemo {
   public static void main(String[] args) {
      String str1 = "tutorials point", str2 = "http://";
      CharSequence cs1 = "int";

      // string contains the specified sequence of char values
      boolean retval = str1.contains(cs1);
      System.out.println("Method returns : " + retval);

      // string does not contain the specified sequence of char value
      retval = str2.contains("_");
      System.out.println("Methods returns: " + retval);
   }
}

輸出

Method returns : true
Methods returns: false

更新於: 26-2-2020

163 次瀏覽

開啟你的 職業生涯

完成本課程,獲得認證

開始
廣告
© . All rights reserved.