Meaningless Drivel is fun!
The moose likes Associate Certification (OCAJP 7/8) 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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7/8)
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: 989
See the code in this post.
Chan Ag

Joined: Sep 06, 2012
Posts: 1089
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. ]
subject: Java pass by reference
It's not a secret anymore!