How do I check if a string contains a specific word?

Category: java.lang, viewed: 6K time(s).

The String.indexOf method returns the first index of a substring found in the specified string. If the substring is not found this method returns -1.

package org.kodejava.example.lang;

public class StringContains {
    public static void main(String[] args) {
        String name = "Kode Java";

        //
        // Checks to see if the word "Java" is found in the name
        // variable.
        //
        if (name.indexOf("Java") != -1) {
            System.out.println("Bravo Java!");
        } else {
            System.out.println("Can't find Java");
        }
    }
}