package variables;

public class AboutStrings {

    public static void main(String[] args) {

        /*
         * Strings are Objects
         * They are defined by the String class.
         * A class contains data and methods.
         * Data = pieces of information that are important to objects
         * that are created from that class.
         * Methods = the things that objects of that class can do, its
         * "behaviours".
         * You'll learn more about objects/classes and their data/methods
         * in an upcoming lesson.
         * 
         * The String class has a lot of methods you can use do perform
         * tasks with strings. You can execute these methods on any
         * String object (as long as the object is not "null").
         * 
         * (assume "str" is the name of a valid String variable)
         * str.toLowerCase() - returns a copy of str's value in lower-case
         * str.toUpperCase() - returns a copy of str's value in upper-case
         * str.contains(val) - returns true if str contains val,
         * false if str doesn't contain val
         * str.length() - returns the number of characters (including spaces,
         * symbols, etc) in str
         * You'll probably learn other methods later in the course
         */

        String str = "1, 2, 3: I love Java!";

        System.out.println(str);
        System.out.println(str.toLowerCase());
        System.out.println(str.toUpperCase());

        System.out.println("contains()");
        System.out.println(str.contains("foo"));
        System.out.println(str.contains("Java"));
        System.out.println(str.contains("!"));

        System.out.printf("length: %d\n", str.length());

        System.out.println("charAt()");
        System.out.println(str.charAt(0));
        System.out.println(str.charAt(9));
        // crashes: string index is out of bounds
        //System.out.println(str.charAt(25));

        System.out.println("indexOf(), lastIndexOf()");
        // Exercise: what do you think the indexOf() method does?
        System.out.println(str.indexOf("1"));
        System.out.println(str.indexOf("Java"));
        System.out.println(str.indexOf("foo"));
        System.out.println(str.lastIndexOf(" "));

        System.out.println("substring()");
        System.out.println(str.substring(0, 7));
        System.out.println(str.substring(9));
        System.out.println(str.substring(str.indexOf("Java")));

    }
}
