there is NO SUCH THING as pass by reference in
java. EVERYTHING is pass by value.
What you must understand is exactly WHAT is being passed.
when you say
Integer iInt = new Integer(2);
you are creating two things. you are creating the Integer object that has a value of 2, which lives on the heap. this can be thought of as a house you have built somewhere.
you also create a REFERENCE to the object, that you have called iInt. that points to the object. It's like having a slip of paper with your house's address on it.
when you say
Integer yInt = iInt;
you are saying "create a new reference and copy the value from the old reference onto it". In other words, you are copying your home address from the paper labeled "iInt" onto a paper labeled "yInt". You have two slips of paper, both of which have the same address on them.
now you do this:
iInt = new Integer(2);
you build a SECOND home. You write the address on the iInt piece of paper, erasing the old address. This in no way effects what is written on the other slip.
it's the same with Strings, or Maps, or any other object.
[ October 02, 2007: Message edited by: Fred Rosenberger ]