Java – String contains() method example


Sequence of characters in String can be find by contains() method in java. contains() method return value in boolean. If character of sequence is found in string, it will return true, otherwise false. Use of String contains() in java is shown below.

Example of String contains() in java

public class StringContainsExample {

    public static void main(String[] args) {
        String string="java string contains character";
        boolean checkContains1=string.contains("ja");
        boolean checkContains2=string.contains("xa");
        System.out.println("check contains string 1 :"+checkContains1);
        System.out.println("check contains string 2 :"+checkContains2);


check contain string 1 :true
check contain string 2 :false



One Response to “Java – String contains() method example”

  1. Julian says:

    I have a question..

    how to do this.

    String myString=”lol”;
    JOptionPane.ShowMessageDialog(null, “jajajaj”);

    how to put this char ‘ in the method .contains(” ‘ “)

Leave a Reply