This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes ArrayList Problems, Help needed Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "ArrayList Problems, Help needed " Watch "ArrayList Problems, Help needed " New topic
Author

ArrayList Problems, Help needed

edu njoro
Greenhorn

Joined: Mar 23, 2011
Posts: 2
Help needed please.
The Arraylist, det, below behaves as if I am adding the same object again and again. Clearly within the while loop
I am creating a new instance of the Detail class on each iteration. Using this instance I am able to set the various properties.
However, the code that follows the while loop i.e. the for..each give me the same value x times, x being the number of records
in the resultset rs.


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16687
    
  19


Do your setter methods make copies of your gc, un, uname, and uno objects? Or are they pointing to the objects that you pass?

In the second case, you will create an array list of different detail objects -- all of which are pointing to the same gc, un, uname, and uno object.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
edu njoro
Greenhorn

Joined: Mar 23, 2011
Posts: 2
Henry,

You are Great!, I struggled with this for hours not ending.

I just needed to create a new instance of the gc,uno,un and uname objects in each iteration.

Thanks Henry!!!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: ArrayList Problems, Help needed
 
Similar Threads
Scanner help
Learning Project 2
Create Object in DoWhile Send to Arraylist
JSTL+Servlet+beans
confused abut Enhanced For loop