File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 892
See the code in this post.
Chan Ag

Joined: Sep 06, 2012
Posts: 1013
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:
subject: Java pass by reference