concept StringBuilder class in category java

This is an excerpt from Manning's book Get Programming with Java.
This lesson introduces the topic of strings in Java. In Java, strings are objects. A string represents as a sequence of individual characters, such as a word or sentence. The String class is widely used in Java and has over sixty methods and thirteen constructors. in addition to the String class, Java also has a StringBuilder class.
To explain the methods that facilitate these actions in the StringBuilder class, Listing 9.2 shows a complete program that uses some of these methods. This program asks the user to enter a word or phrase, then checks to see if the string is considered a palindrome. A palindrome is a word or sentence that is spelled the same way forward and in reverse, such as racecar, civic, level, kayak, noon, and so on.
Notice that I do not need to import the StringBuilder class, it is also part of the java.lang package which is automatically imported for all Java programs.
Listing 9.2 This program tests a string to see if it is a palindrome
1. import java.util.Scanner; 2. public class FunWithStrings { 3. public static void main(String[] args) { 4. Scanner in = new Scanner(System.in); 5. boolean isPalindrome = true; 6. StringBuilder text = new StringBuilder(); //#A 7. System.out.print("Enter a sentence/word and I will test to see if it is a" + 8. + " palindrome: "); 9. String input = in.nextLine(); 10. text.append(input); //#B 11. StringBuilder textReversed = new StringBuilder(); //#C 12. textReversed.append(input).reverse(); //#C 13. for (int i = 0; i < input.length(); i++) { //#E 14. if (text.charAt(i) != textReversed.charAt(i)) { //#E 15. isPalindrome = false; //#E 16. break; //#E 17. } //#E 18. } //#E 19. System.out.println("original: " + text + " length: "+text.length()); 20. System.out.println("reversed: " + textReversed); 21. if (isPalindrome) { 22. System.out.println(text + " is a palindrome! "); 23. } 24. else 25. System.out.println(text + " is not a palindrome, try again :-) "); 26. } 27. }In Listing 9.2, the code starts by creating a new StringBuilder object, text. Then using the .append method from the StringBuilder class, the word/phrase entered by the user is added to the empty object. To test if this is a palindrome, the program creates a second object that contains the same value in reverse. Notice that line 11 creates a second StringBuilder object that is then assigned the value of the original string in reverse order using the methods on line 12. Now it is easy to test if this is a palindrome but just comparing the two strings character for character to see if they are the same.