Results 1 to 6 of 6

Thread: What is mutable and immutable Strings

  1. #1
    Join Date
    Dec 2009
    Posts
    67

    What is mutable and immutable Strings

    Hello Friends,

    I am studying Java programming language. In which I have one query about he strings. What is mutable and immutable String. As per my java knowledge the string the collection of one or more characters. But don't know anything about the mutable and immutable String. If you have knowledge about the mutable and immutable String then please share withe me. I am waiting for your reply.

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

    re: What is mutable and immutable Strings

    Mutable string are those string which can be append to to the another string. The object of the StringBuffer is always mutable string.There are two states of Mutable strings i.e loose and compact. In these state the strings works like StringBuffer and String. The "java.lang.StringBuilder" is of type mutable and which is useful for to insert or delete or the appending of character.

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

    re: What is mutable and immutable Strings

    The Java string classes are basically of type String & StringBuffer. There are two types of string mutable and immutable. The modification of string is not allowed in "immutable string". While in "Mutable string" we can make modification as per our need. When you try to modify the "immutable string", it will generate an error message. The mutable string is defined using "java.lang.StringBuilder" package which comprises 'StringBuffer' class.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    re: What is mutable and immutable Strings

    All string literals in Java implemented as an instances of the class. Strings are constant, it means it's values can't be modified after they are created. String buffers support mutable strings. The String class of java language comprises character strings. String objects of the java class are immutable as they can be shared. The class String comprises the methods for to comparing strings individual. It is also used for for to sear a particular strings as well as for extracting sub strings.

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    re: What is mutable and immutable Strings

    The Java programming has special support for to concat string operator ( + ). Which is used for converting other objects into strings. concatenation String is applied by using the StringBuffer class. This class comprises special methods for to append string. The 'toString' is used in the string conversion process. This method of java can be inherited or defined by all classes and all objects from Java programs.

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    re: What is mutable and immutable Strings

    Hi friend,

    Refer following java example to know about the mutable string:
    Code:
    class MyPointD
    {
      public string x='ASDF', y='WERT5;
    
      public void print()
      {
        System.out.println("x = " + x + "; y = " + y );
      }
    }
    
    class PointTester
    {
      public static void main ( String[] args )
      {
        MyPoint ptb = new MyPoint();
    
        ptb.print();
    
        ptb.x = 'vbnm';  ptb.y = 'tghu';
    
        ptb.print();
      }
    }

Similar Threads

  1. How to use Strings in Python
    By Edmund-Windows in forum Software Development
    Replies: 5
    Last Post: 31-12-2010, 06:25 AM
  2. Strings in JavaFX
    By Messenger in forum Software Development
    Replies: 3
    Last Post: 16-07-2010, 04:57 PM
  3. Struct and Strings in C
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 05-04-2010, 12:31 PM
  4. What are an Immutable Objects in Java?
    By Silent~Kid in forum Software Development
    Replies: 4
    Last Post: 19-02-2010, 06:35 AM
  5. Mutable Image in Java
    By samualres in forum Software Development
    Replies: 3
    Last Post: 10-12-2009, 01:21 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,484,373.28323 seconds with 17 queries