Illuminatiiiiii
1/13/2019 - 8:30 PM

More String Methods

Java Library Ep. 4:

public class Main {

    public static void main(String[] args) {

        //Finding a substring
        String s1 = "Strings seem magical";
        System.out.println(s1.substring(8));
        System.out.println(s1.substring(8, 12));

        //Concatenation with methods
        String s2 = "death";
        String s3 = s2.concat("life");
        System.out.println(s3);

        //Replacing characters
        String s4 = "Hello".replace('l', 'w');
        System.out.println(s4);

        //Getting rid of extra space (https://stackoverflow.com/questions/51266582/difference-between-string-trim-and-strip-methods-in-java-11)
        String s5 = "     Booty     ";
        System.out.println(s5.trim());
        String s6 = "       Grape           ";
        System.out.println(s6.strip());
        System.out.println(s6.stripLeading());
        System.out.println(s6.stripTrailing());

        //Case changing
        String s7 = "car";
        String s8 = "ABRACADABRA";
        System.out.println(s7.toUpperCase());
        System.out.println(s8.toLowerCase());

        //Joining Strings
        String result = String.join("|", "I", "like", "bears");
        System.out.println(result);

        // ---List---
        //substring() - allows you to extract a string from a string
        //concat() - concatenate two strings
        //replace() - replace all occurrences of a character with another character
        //trim() - remove any extra spaces from the string
        //strip() - trim but better because it takes into account other types of space
        //stripLeading()
        //stripTrailing()
        //toUpperCase() - all characters are upper case
        //toLowerCase() - all character are lower case
        //join() - concatenates strings with a chosen "delimiter"

    }
}