elias

1
reputation
3

Why I don't like stringbuilder:

public class Main {

public static void main(String[] args) {
    StringBuilder sb = new StringBuilder();
    sb.append("test");
    sb.append(" and another test");
    System.out.println(sb + " (StringBuilder)");
    String thing = "test";
    thing = thing + " and another test";
    System.out.println(thing + " (String)");
    sb.append("A "); // puts at the end. how do you put something at the start???????????? if you answer the question, be honest; you had to look it up.
    System.out.println(sb + " (StringBuilder)");
    thing = "A " + thing;
    System.out.println(thing + " (String)");
    /*sb.replace("and another", "and then another");*/ // NOT POSSIBLE WITH STRINGBUILDER, REQUIRES IT TO BE INTEGERS NOT STRINGS!! THEREFORE WE NEED TO REPLACE DURING PRINTING!!!
    System.out.println(String.valueOf(sb).replace("and another", "and then another") + " (StringBuilder)");
    thing = thing.replace("and another", "and then another");
    System.out.println(thing + " (String)");
}
}