Java String contains() method example.

Java 8Object Oriented ProgrammingProgramming

The contains() method of the String class returns true if and only if this string contains the specified sequence of char values.

Example

 Live Demo

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);
   }
}

Output

Method returns : true
Methods returns: false
raja
Published on 12-Feb-2018 10:14:58
Advertisements