• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

ArrayList Hijinx and the S.O.P statement

 
Ranch Hand
Posts: 201
1
Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic