Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

String and String Buffer

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Ans is :s=aaa sb=bbbaaabbb

The value of String object is understandable because strings are immutable so any changes made in the mehod will not effect the original String.
But why does setting the StringBuffer to null does not effect its value.
After all StringBuffr is not immutable and any changes made to it in the method should have an effect in the original StringBuffer object.
i know i am not getting it right.
please help
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,



After the append, the object where "sb" references to has a value of "bbbaaabbb". "sb = null;" removes the reference to that object, but the original "sb" (that one in the main method) still refers to that object. The whole clue is, that when you pass an object as an argument to a method, you pass a copy of the reference to that object. So by setting the copy reference to null, doesn't mean that the original will be set to null..

Greetz,
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first of al have a look at this example on a different topic.

parameter passing

Its a pretty neat illustration.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am overwhelmed by the postitive spirt of this forum and by the usefulness of JavaRanch.

I am new to Java and just wanted to thank Swamy for his excellent Flash application that demonstrates how variables are passed in Java.

http://www.geocities.com/mcglonec1978/javacert/paramPassing.html

I hope I can contribute to others benefit in the future once I am more skillful.

Jerry
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic