Results 1 to 6 of 6

Thread: Handling String

  1. #1
    Join Date
    Aug 2013
    Posts
    108
    Rep Power
    0

    Default Handling String

    From the complete reference book:
    One last point: To say that the strings within objects of type String are unchangeable means that the contents of the String instance cannot be changed after it has been created. However, a variable declared as a String reference can be changed to point at some other String object at any time.
    Sentence 1 contradicts with the Sentence 2. What is happening? Will appreciate an example.
    Last edited by JosAH; 08-26-2013 at 05:49 PM.

  2. #2
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Handling Spring

    String are immutable, mean once you created a string you cannot change it ...e.g
    Java Code:
    String s = "some string";
    s.substring(0,3);
    System.out.print(s); // still prints "some string"
    String a = s.substring(0,3);
    System.out.print(a); // prints "som"
    s += " new";
    System.out.print(s); // prints "some string new"
    In "+=" a new object of string is created and "s" is referenced to that new object.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,912
    Rep Power
    5

    Default Re: Handling String

    Say Foo is an immutable object.

    Java Code:
    Foo obj1 = new Foo();
    Foo obj2 = obj1;
    For any immutable object Foo, it is impossible to alter obj2 such that obj1 reflects the change.

    Java Code:
    String str1 = "Hello, World!";
    String str2 = str1;
    No methods exists where you can alter str1 by manipulating str2.

    But you may still assign any string you want to either variable. Then they will be different objects (not taking into account
    interning of string objects).


    Regards,
    Jim
    Last edited by jim829; 08-26-2013 at 06:29 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,912
    Rep Power
    5

    Default Re: Handling String

    You may want to change your title in coordination with the moderators. Handling Spring is different than Handling String. Spring is a framework used in web design. Folks may be ignoring your thread based on the title.

    Regards,
    Jim
    Last edited by jim829; 08-26-2013 at 06:30 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Handling Spring

    Quote Originally Posted by jim829 View Post
    You may want to change your title in coordination with the moderators. Handling Spring is different than Handling String. Spring is a framework used in web design. Folks may be ignoring your thread based on the title.
    I changed the typo in the title; it didn't change the title in the replies though; oh well ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,260
    Rep Power
    6

    Default Re: Handling String

    Quote Originally Posted by suhaas.mohandos@gmail.com View Post
    Sentence 1 contradicts with the Sentence 2.
    No, it doesn't - you just claim it does, but because you say so doesn't make it the truth.

    Apparently you don't understand yet what the difference is between an object and a reference to an object. That would be quite an important thing to research.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. File handling
    By Dayanand in forum New To Java
    Replies: 3
    Last Post: 03-22-2011, 05:20 PM
  2. Replies: 1
    Last Post: 12-27-2010, 06:21 PM
  3. IO handling
    By sonalim in forum Advanced Java
    Replies: 2
    Last Post: 10-08-2010, 05:00 AM
  4. session handling
    By priyanka_t in forum JavaServer Pages (JSP) and JSTL
    Replies: 10
    Last Post: 08-11-2009, 01:32 PM
  5. SWT Event Handling
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-30-2007, 01:21 PM

Posting Permissions

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