Java String.contains()方法

Java String.contains()包含包括, 返回Boolean值,当且仅当此字符串包含指定的char值序列

声明:

以下是声明java.lang.String.contains()方法
public boolean contains(CharSequence s)

参数:

s-- This is the sequence to search for.

返回值:

如果此字符串包含,此方法返回true,否则返回false。

异常:

NullPointerException-- if s is null.

实例:

 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: " + retval); //输出false
             }
        }
contains返回的是布尔类型true 和false,包含的话就返回true,不包含的话就返回false


你可能感兴趣的:(Java String.contains()方法)