How would you convert the functions of a String Buffer to a String Builder. I know the two are very similar but I can't change my StringBuffer sb = new StringBuffer(); to StringBuilder sb = new StringBuilder(); without getting an abundance of error messages.
Here is a little code I made:
StringBuffer sb = new StringBuffer(); //Create a new String Buffer with nothing in it
for (int n = 0; n < 1; n++) {
sb.append("Billy "); //Add (first name)
sb.append("Scranner"); //Add (surname)
System.out.println(sb); //Print the string buffer
sb.insert(5," D"); //Insert " D" at the 4th character
System.out.println(sb); //Print the String Buffer with the middle initial
sb.delete(5, 7); //Delete the character line from 4 to 6
sb.reverse(); //Reverse the String Buffer
System.out.println(sb); //Print the reversed String Builder
I apologize if my question seems unclear, TLDR; I would like to know how to obtain the same output that I get from this program using a String Builder instead of the String Buffer.
Here is what the program outputs:
Billy Scranner
Billy D Scranner
rennarcS ylliB
EDIT: This is the output I get when I replace Buffer with Builder:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method append(String) is undefined for the type StringBuilder
The method append(String) is undefined for the type StringBuilder
The method insert(int, String) is undefined for the type StringBuilder
The method delete(int, int) is undefined for the type StringBuilder
The method reverse() is undefined for the type StringBuilder
String builder? @Kayaman