Things to Know Part 3

Strings:

        -immutable (i.e. can't be changed)

        -can be concatenated with += or with .concat()

        -does not change string but returns a new string with changes

        -chars are indexed starting at 0

        -substring(start, end); returns smaller version of string. First parameter is starting char element inclusive, the second is ending char element exclusive.

        

        common methods:

                int charAt(int)

                int compareTo(String)

                String concat(String)

                int indexOf(int); int indexOf(int, int); int indexOf(String); int indexOf(String, int)

                boolean isEmpty()

                int length()

                String substring(int, int)

                String toLowerCase()

                String toUpperCase()

StringBuilder:

        -mutable (i.e. can be changed)

        -substring doesn't change value but append(), delete(), and insert() do.

        -StringBuilder methods return current instance of the value.

        common methods:

                StringBuilder append()

                int charAt()

                int indexOf()

                StringBuilder insert()

StringBuilder insert()

StringBuilder reverse()

String substring() // <-- notice it does not return a StringBuilder.                

StringBuffer:

        -same as StringBuilder but thread safe.

        

== vs .equals():

        -== checks if two references are pointing to the same object.

        -.equals() depends on implementation

        -String .equals() checks that all characters are the same.

Arrays:

        -arrays are mutable in Java.

-One dimensional arrays

        int[] x = {1, 2, 3};

        int[] y = new int[3];

        

-Multi dimensional arrays

int[][] x = {{1, 2, 3}, {4, 5, 6}};

int[][] y = new int[3][3];

        -Indexes start at 0

                System.out.print(x[1]); //<--prints 2

                System.out.print(x[3]); //<--array out of bounds

        

ArrayList:

                ArrayList<String> list = new ArrayList<String>();

                ArrayList<String> list = new ArrayList<>();

-can increase and decrease in size

-must have class in angled brackets <>. No primitive data types.

common methods:

        void add(<>)

        void clear()

                int index of(<>)

                boolean isEmpty()

                <> remove()

                void set(int, <>)

                List<> subList(int, int)

                <>[] toArray()

Autoboxing:

        -automatically forcing a primitive data type into a wrapper object.

                int x = 7;

                Integer ex = x;

                //int x is autoboxed into an Integer

Date and Time:

        LocalDate:

                -cannot be casted to LocalTime

                -cannot contain time fields

        LocalTime:

                -cannot be casted to LocalDate

                -cannot contain date fields

        -can add and subtract time. The result gets returned.

        DateTimeFormatter:

                -used to format dates and times to a specific format





source:

Boyarsky, Jeanne, and Scott Selikoff. OCA Oracle Certified Associate. Study Guide. John Wiley & Sons, 2015.