How do I check a string ends with a specified word?

Date: 2010-09-16. Category: java.lang examples. Hits: 5K time(s).

The String.endsWith() method can be use to check if a string ends with a specified suffix. It will returns a boolean true if the suffix is found at the end of the string object.

package org.kodejava.example.lang;

public class EndsWithSample {
    public static void main(String[] args) {
        String str = 
                "The quick brown fox jumps over the lazy dog";

        //
        // well, does the fox jumps over a lazy dog?
        //
        if (str.endsWith("lazy dog")) {
            System.out.println("The dog is a lazy dog");
        } else {
            System.out.println("Good dog!");
        }
    }
}