Thursday, 13 July 2017

String contains in java ~ foundjava

Java String contains

The java string contains() method searches the sequence of characters in this string. It returns true if sequence of char values are found in this string otherwise returns false.

Signature

The signature of string contains() method is given below:
  1. public boolean contains(CharSequence sequence)  

Parameter

sequence : specifies the sequence of characters to be searched.

Returns

true if sequence of char value exists, otherwise false.

Throws

NullPointerException : if sequence is null.

Java String contains() method example

  1. class ContainsExample{  
  2. public static void main(String args[]){  
  3. String name="what do you know about me";  
  4. System.out.println(name.contains("do you know"));  
  5. System.out.println(name.contains("about"));  
  6. System.out.println(name.contains("hello"));  
  7. }}  

true
true
false

No comments:

Post a Comment