Test if a String Contains Specific Words in Java



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

Example

Live Demo

public class Sample {
   public static void main(String args[]){
      String str = "Hello how are you welcome to tutorialspoint";
      String test = "tutorialspoint";
      Boolean bool = str.contains(test);
      System.out.println(bool);
   }
}

Output

true
Updated on: 2020-02-26T09:56:55+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements