Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes LinkedList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "LinkedList" Watch "LinkedList" New topic
Author

LinkedList

Nick Stevens
Greenhorn

Joined: Nov 13, 2004
Posts: 15
Hello,

I'm trying to make a hash table that will store
many sets of four integers. As part of this
I thought I could store each set of integers
in an 4 x 1 integer array and then store the
arrays in a linked list. I've added arrays
okay using the LinkedList class but I can't work
out how to access the arrays once they are in
the linked list. Here's some of the code:

int[] arrayOne = new int[4];
int[] arrayTwo = new int[4];

List aList = new LinkedList();

aList.add(arrayOne);
aList.add(arrayTwo);

int listIndex = aList.indexof(arrayTwo);

// This line doesn't work:
int[] myArray = (int[])aList.get(listIndex);


Any help would be much appreciated!
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
What do you mean by "this line doesn't work"? Do you get compiler errors? If so, what are the errors? If not, does it run? What output do you get and how does it differ from what you expect?

At a glance, the syntax looks correct, so you need to answer these questions in order for us to help you. Please provide as much information about the exact problem as you can.

Layne


Java API Documentation
The Java Tutorial
Nick Stevens
Greenhorn

Joined: Nov 13, 2004
Posts: 15
Thanks a lot for your reply - you're right it *does* work!
I feel stupid now. I tried lots of other things before I
tried that last line and my code was a lot messier with many
extra lines and I didn't test the last line properly. Ahem.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Nick Stevens:
I tried lots of other things before I
tried that last line and my code was a lot messier with many
extra lines and I didn't test the last line properly. Ahem.
Yellow Card for Nick!

To clear it, please choose another post in this forum (or any other) and try to help the poster with their problem. Then it will be cleared.
Nick Stevens
Greenhorn

Joined: Nov 13, 2004
Posts: 15
A yellow card. Doh! How will I know when I've posted a reply that is deemed sufficiently useful?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Nick Stevens:
How will I know when I've posted a reply that is deemed sufficiently useful?
Only you can be the judge of that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LinkedList
 
Similar Threads
Implementing a Set using Linked List
Iteration speed of Collections
pollFirstXxx() question
an Object array
newbie help please with arrays