Difference between String and StringBuffer
There are many differences between String and StringBuffer. A list of differences between String and StringBuffer are given below:
Performance Test of String and StringBuffer
Time taken by Concating with String: 578ms Time taken by Concating with StringBuffer: 0ms
The above code, calculates the time required for concatenating a string using the String class and StringBuffer class.
String and StringBuffer HashCode Test
As we can see in the program given below, String returns new hashcode while performing concatenation but the StringBuffer class returns same hashcode.
Hashcode test of String: 3254818 229541438 Hashcode test of StringBuffer: 118352462 118352462