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

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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic