Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

LinkedList

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Nick Stevens
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A yellow card. Doh! How will I know when I've posted a reply that is deemed sufficiently useful?
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic