This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have an arraylist with some elements in one method. In a second method (independent from the first)Iam trying to display this list. The result is only the last element is printed (number of times = list size)
Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.
The problem is that there's only one Value object here. You keep changing its contents and re-adding it to the ArrayList, so the ArrayList contains many references to the same Value object. As a result, when you print all those out, you see the same thing printed many times. You need to create new Value objects to put in the list -- don't try to reuse the same one.