Illuminatiiiiii
1/20/2019 - 9:00 PM

StringBuffer and StringBuilder

        StringBuffer string1 = new StringBuffer(); //Reserves 16 characters
        StringBuffer string2 = new StringBuffer(4); //Reserves 4 characters
        StringBuffer string3 = new StringBuffer("I'm a string"); //Creates String Buffer with the provided string, but adds room for 16 more characters

        //String Buffers pre-allocate room for more characters so that reallocations dont need to happen
        //frequently, every time you change the string

        System.out.println(string3.length());
        System.out.println(string3.capacity());

        StringBuffer s4 = new StringBuffer("Republicans are #1");
        System.out.println(s4.length());
        s4.setLength(20);
        System.out.println(s4);
        s4.setLength(16);
        System.out.println(s4);

        StringBuffer s5 = new StringBuffer("Shapiro");
        System.out.println(s5.charAt(2));
        s5.setCharAt(3, 'k');
        System.out.println(s5);

        s5.append("Ben").append(30);
        System.out.println(s5);

        StringBuffer s6 = new StringBuffer("I Java");
        s6.insert(2, "like ");
        System.out.println(s6);

        System.out.println(s6.reverse());

        StringBuffer s7 = new StringBuffer("Constitution");
        System.out.println(s7.deleteCharAt(1));
        System.out.println(s7.delete(7, 11));

        StringBuffer s8 = new StringBuffer("Dolphin");
        System.out.println(s8.replace(0, 3, "Doodoo"));

        //--List--
        //length() - How many character are in the string
        //capacity() - The amount of space available for characters(usually length + 16)
        //setLength() - Set the maximum amount of characters in the string
        //setCharAt() - Replace a specific character in the stringbuffer
        //append() - Add a string or an objects string version to the end of the stringbuffer
        //insert() - Add a string into the stringbuffer
        //reverse() - Reverse a stringbuffer
        //delete() - Delete a substring within the stringbuffer
        //deleteChatAt() - Delete a specific character
        //replace() - replace a substring within the stringbuffer