View RSS Feed

Recent Blogs Posts

  1. String vs. StringBuffer

    by , 01-08-2012 at 12:26 PM
    Following are the major differences between these 2:

    • String is immutable as compared to StringBuffer. You need to create a new instance to replace an object.

    Java Code: This is an example of immutable string
    //Inefficient version using immutable String
    String output = “Some text”
    Int count = 100;
    for(int I =0; i<count; i++) {
    output += i;
    }
    return output;
    • StringBuffer is mutable. Also it is not synchronized.

    Java Code: This is an example of mutable string
    //More
    ...

    Updated 01-14-2012 at 07:42 PM by Java String

    Categories
    String , StringBuffer