The difference between String StringBuilder StringBuffer ~~~

   The difference between String StringBuilder StringBuffer ~~~

String is a string constant, once created, it cannot be changed;

StringBuilder and StringBuffer are string variables that can be increased or decreased later;

StringBuilder is thread-unsafe, and the method implementation in it does not use the keyword synchronized, which is suitable for single-threaded use;

StringBuffer is thread-safe, and the methods in it are implemented using the synchronized keyword, which is suitable for multi-threading.

Running speed: String < StringBuffer < StringBuilder


eg:StringBuilder sb = new StringBuilder().append("abc").append("bcd");

System.out.println(StringBuilder.toString(sb));

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325726845&siteId=291194637