Difference between StringBuffer and StringBuilderJava provides three classes to represent a sequence of characters: String, StringBuffer, and StringBuilder. The String class is an immutable class whereas StringBuffer and StringBuilder classes are mutable. There are many differences between StringBuffer and StringBuilder. The StringBuilder class is introduced since JDK 1.5. A list of differences between StringBuffer and StringBuilder is given below:
StringBuffer ExampleBufferTest.java Output: hellojava StringBuilder ExampleBuilderTest.java Output: hellojava Performance Test of StringBuffer and StringBuilderLet's see the code to check the performance of StringBuffer and StringBuilder classes. ConcatTest.java Output: Time taken by StringBuffer: 16ms Time taken by StringBuilder: 0ms Next TopicHow to create immutable class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India