View RSS Feed

Recent Blogs Posts

  1. String vs. StringBuffer

    by , 01-08-2012 at 11:26 AM
    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 06:42 PM by Java String

    Categories
    String , StringBuffer
  2. Wrapping Strings

    by , 05-21-2011 at 10:50 PM (My Java Tips)
    Its always useful to wrap strings if they are too long. This provides better readability. Eclipse has support for this.

    String literals can wrapped when you edit them. Place your cursor at the point of literal where you want to wrap and press Enter. For example:

    Java Code:
    String message= "Java is fun to learn and it sure is a popular programming language.";
    I kept the cursor at ‘sure’ and pressed enter key. The String was changed to: ...
    Tags: string Add / Edit Tags
    Categories
    Eclipse