This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Storing data from different methods into LinkedList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Storing data from different methods into LinkedList" Watch "Storing data from different methods into LinkedList" New topic

Storing data from different methods into LinkedList

Laura Balsamo

Joined: Oct 16, 2011
Posts: 3
Hello all,

Thank you in advance for the assistance. I have a code that I must edit. Currently it features a LinkedList structure with multiple methods throughout various classes adding data into this LinkedList and then printed at the end. I am tasked with changing this so, instead of these methods adding data to the LinkedList throughout the program, it only adds the data at the end (in a separate test class). My trouble is that this structure makes perfect sense to me so I don't know where to start. How do I get data from different methods into this LinkedList without continuously appending it as the methods are executed?

Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
The only thing I can think of seems too obvious to be the answer, but you haven't given a lot of details about why someone wants you to do this. It is possible they didn't give you many details either.

If for some reason they want a linked list that gets all its additions "all at once", and the various additions all come from different methods, then all I can think of is to accumulate them in a different linked list, and then transfer them from one to the other "all at once".

I suppose if someone wanted to lock the linked list from alterations before the first addition until after the last one, but didn't want to lock for execution of all the methods, then it might make sense to do this. But it's just a shot in the dark.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46437
And welcome to the Ranch
I agree. Here's the link:
subject: Storing data from different methods into LinkedList
It's not a secret anymore!