check if word contains only letters java code example

Example 1: How do I check if a string contains a specific word?

$a = 'Hello world?';

if (strpos($a, 'Hello') !== false) { //PAY ATTENTION TO !==, not !=
    echo 'true';
}
if (stripos($a, 'HELLO') !== false) { //Case insensitive
    echo 'true';
}

Example 2: java string contains char

/*
    This method returns true if the given string contains
    the char n. It is necessary due to the
    obsolescence of some compilers, which requires us
    to write our own contains method.
    */
    public static boolean contains_char (String main, char secondary)
    {
        boolean contains_result = false;
        for (int i = 0 ; i < input.length () ; i++)
        {
            if (input.charAt (i) == secondary)
            {
                contains_result = true;
                break;
            }
        }
        return contains_result;
    }

/*
for two chars:
*/
public static boolean contains_dualchar (String main, String secondary)
    {
        boolean contains_result = false;
        for (int i = 0 ; i < input.length () ; i++)
        {
            if (input.charAt (i) == secondary.charAt (0))
            {
                if (input.charAt (i + 1) == secondary.charAt (1))
                {
                    contains_result = true;
                    break;
                }
            }
        }
        return contains_result;
    }

Tags:

Java Example