This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extracting values from an ArrayList?

 
D diller
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's my situation so far:

I have created an ArrayList which users add values to; a String and an integer for each element in the ArrayList. I am using the .get(x) method with a user-inputted variable (x) to select a specific element ID. Fantastic. Now I'd like to get just the integer value (say, for example, a variable the user inputs earlier which is named z) that was input into the ArrayList for that particular set of values. Can this be done?
 
D diller
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Upon reviewing it all, I think I may need to use a Hashmap...
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by D diller:
Upon reviewing it all, I think I may need to use a Hashmap...


Yes, sounds like you want a Map.
List.indexOf(Object) sounds useful (but not ideal) for your use.
 
D diller
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, I just redid the entire program using a HashMap instead and I've gotten further in 7 hours of programming than I did in about four times that much because once I wasn't scared of HashMaps, it was a lot easier to use them
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic