Java Example – Java String Contains example

Java Tutorial for Beginners
Java Tutorial for Beginners

In this post we will see Java String contains example. This example shows how to use contains method of Java String class.
String.contains Returns true if and only if this string contains the specified sequence of char values.

To check whether the string contains specified character sequence use,  String.contains  method of Java String class.

 * Java String Contains example by
public class JavaStringContainsExample {
    public static void main(String args[]) {
        String string1 = "Hello World";
        String string2 = "Hello";

        boolean boolFound = string1.contains(string2);
        System.out.println("String contains another string? : " + boolFound);


Output :
String contains another string? : true


Partner Sites

Be the first to comment

Leave a Reply

Your email address will not be published.