• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

String buffer

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


In the above code
I expect the value being chaged in the methods m1 and m2 is local StringBuffres .but the result is different .
can any one help me out where I am goig wrong.....
[ February 04, 2006: Message edited by: manogna edintipal ]
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In java all variables will be passed as "Pass By Reference". In C++ it is "Pass By Value". Don�t get confusion about these two concepts

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

and what happens if we use String instead of String Buffer.
 
Kiran Chand Panga
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


String object is immutable. Once you have assigned a String value that value can never change.
for Ex:
String s = new String("Infosys");
System.out.println(s); // Infosys
s.concat(Technologies"); // it creates the temporary new String object and appens the value and it will not add to Original String
System.out.println(s); // Infosys
System.out.println(s.concat(Technologies")); //Infosys Technologies(Temporary string will displayed)

Because of this problems only Sun as introduced the StringBuffer concepts
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String does not have an append method. But if you were to modify your program so as to use String instead of StringBuffer.



You will get an output: ABAA

But the output in the StringBuffer eample will be ABABCABC.

[ February 04, 2006: Message edited by: Abid Sami ]
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic