wood burning stoves 2.0*
The moose likes Associate Certification (OCAJP 7) and the fly likes Java pass by reference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7)
Bookmark "Java pass by reference " Watch "Java pass by reference " New topic

Java pass by reference

joao ferreira

Joined: Feb 23, 2009
Posts: 8

//result s=aaa sb=bbbaaabbb
i=5 j=7

Why the StringBuilder sb change the value?
E Armitage

Joined: Mar 17, 2012
Posts: 888
See the code in this post.
Chan Ag

Joined: Sep 06, 2012
Posts: 1000
Why the StringBuilder sb change the value?

Because sb is pointing to a mutable object. I hope you know why the variable s prints the same value.

[ Edit - I'd suggest to read the entire thread E Armitage is referring to. ]
I agree. Here's the link: http://aspose.com/file-tools
subject: Java pass by reference
Similar Threads
Passing String into a method causes the method to have it's own copy, correct?
String and String Buffer
Problem with Stringbuilder
pass value or pass reference