Results 1 to 4 of 4

Thread: Difference between String and StringBuffer.

  1. #1
    Join Date
    Nov 2009
    Posts
    50

    Difference between String and StringBuffer.

    Hi,
    I recently started learning java language. Our sir had teach us String and StringBuffer but can't understand difference between them. So if you have any knowledge on String and StringBuffer please help me.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Difference between String and StringBuffer.

    Java language gives you two classes StringBuffer and String. The StringBuffer class is create to make any changes in character. String class is used to modified character string that unable to changed. In general StringBuffer class is faster than String class.

    Eg. of string:

    String S = new String ("Hello to all ");
    S+= "How are you";

    Eg. of StringBuffer:
    StringBuffer S = new StringBuffer ("Welcome to my world ");
    S.append("Techarena");

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Difference between String and StringBuffer.

    1.Objects of string class are immutable and constants while objects of StringBuffer class are not immutable and constants.

    2.We use modifiable and growable string in StringBuffer Class where as constant strings are used in String class.

    3.Once we create string then we can not modified them where as we can modified StingBuffer objects.

    4.values of StringBuffer class are manipulated at compile time while values of String class are manipulated only at run time.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Difference between String and StringBuffer.

    1.The main difference between String and stringbuffer is that stringbuffer object is thread safe while string is not.

    2.In String we can not change content while in StringBuffer we can change content.

    3.We can not create sub class of string where as we can create sub class of StringBuffer

    4.In string we use compareTo() method to compare two string while in StringBuffer we don't have this method.

    5.In string class we don't have reverse() method while in StringBuffer we have reverse() function.

Similar Threads

  1. Empty StringBuffer in java
    By TechGate in forum Software Development
    Replies: 4
    Last Post: 08-03-2010, 01:16 PM
  2. Differentiation among StringBuffer and StringBuilder class
    By Ram Bharose in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 02:20 PM
  3. Difference between string and stringbuilder?
    By Quique in forum Software Development
    Replies: 5
    Last Post: 27-11-2009, 07:37 PM
  4. How to Manipulate String using PHP String Functions
    By ComPaCt in forum Software Development
    Replies: 3
    Last Post: 21-09-2009, 09:07 AM
  5. Difference between capacity and size functions of string class
    By DimitrisLiatsos in forum Software Development
    Replies: 5
    Last Post: 25-10-2008, 05:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,447,461.92647 seconds with 17 queries