Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By superhaNds

Thread: is String immutable in Java

  1. #1
    james12 is offline Member
    Join Date
    Jun 2014
    Posts
    37
    Rep Power
    0

    Default is String immutable in Java

    Hi iam a java fresher.i want to know weather String is immutable in Java or not

  2. #2
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    265
    Rep Power
    2

    Default Re: is String immutable in Java

    Reading the documentation clearly will answer such questions.

    String (Java Platform SE 7 )

    Yes it is.
    gimbal2 likes this.

  3. #3
    Join Date
    Jul 2014
    Location
    United States
    Posts
    7
    Rep Power
    0

    Default Re: is String immutable in Java

    In Java, strings are object. There are many different ways to create a String object. One of them is using string literals.

    Each time a string literal is created, JVM checks the string constant pool first. If string already exist in the pool, a reference to the pool instance is returned. Sometime it is possible that one string literals is referenced by many reference variable. So if any of them change the string, other will also get affected. This is the prominent reason why string object is immutable.



    Regards

    [ ad links removed -- mod ]
    Last edited by JosAH; 07-02-2014 at 09:35 AM.

Similar Threads

  1. immutable class
    By yanivdan98 in forum New To Java
    Replies: 3
    Last Post: 02-24-2013, 11:02 PM
  2. Why String is immutable in java?
    By harikrishanyogi in forum New To Java
    Replies: 2
    Last Post: 03-07-2012, 07:20 PM
  3. Why string is immutable in java?
    By jessie143143 in forum Reviews / Advertising
    Replies: 0
    Last Post: 10-15-2011, 02:47 PM
  4. String Immutable
    By jomypgeorge in forum New To Java
    Replies: 18
    Last Post: 12-17-2010, 11:54 AM
  5. What is Immutable in String
    By elektronika in forum New To Java
    Replies: 4
    Last Post: 12-10-2009, 12:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •