• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList Hijinx and the S.O.P statement

 
Ted North
Ranch Hand
Posts: 201
1
Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



How does this output: [3, 7, 5, 9, 1]

I am not understanding how x and y refer to the same ArrayList object...

Does anyone have a simple explanation please?

 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The List reference named x is passed into the doStuff method, and the result is assigned to the List reference named y. But notice that the doStuff method returns the same reference that was passed in. Drawing a picture can help you sort out this kind of puzzle very quickly.
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the picture:
1. z -> x
2. y-> z

Therefore y->x, where-> means refers to.

Hope this helps.
 
Ted North
Ranch Hand
Posts: 201
1
Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thanks all, my colleague helped explain some also...

I want to say again how much I appreciate everyone's responses and help.

I was completely baffled as to how the two collections could relate to each other, when there is not an explicit assignment that says x = y for instance. I think this concept is also something that the new Java programmer has to grasp and memorize like rules for a game like dungeons and dragons or something.

Respectfully,

TN
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic