Java tutorial
public class Main { public static void main(String[] args) { String str = "This is a test"; // Test str, if it starts with "This" if (str.startsWith("This")) { System.out.println("String starts with This"); } else { System.out.println("String does not start with This"); } // Test str, if it ends with "program" if (str.endsWith("program")) { System.out.println("String ends with program"); } else { System.out.println("String does not end with program"); } } }