Write a method that takes in a String and returns the reversed version of the String.
Examples: reverseString("abcde") -> "edcba" reverseString("1") -> "1" reverseString("") -> "" reverse("madam") -> "madam" reverse(null) -> null
You will find the charAt(i) method of the String class and append() of the StringBuilder class useful. Remember - Strings in java are immutable. Each time a String is changed, a new copy of the String is made. For any changes to a String, using a StringBuilder object results in lower memory consumption and faster code.
Iterate across the first String from str.length()-1 to 0, adding the character at index i (using .charAt(i)) to the new StringBuilder object with .append(i). Finally, return the new String using the .toString() method of the StringBuilder object created earlier.