• Post Reply Bookmark Topic Watch Topic
  • New Topic

Returning a specific object from an arraylist  RSS feed

 
Jack Edward
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program that creates a list of specific objects, asks the user to input the name of an object on that list, and returns that object. The only think cant figure out is how to return that specific object after the user has entered the object name.

The name of the list of objects is called myHexList. The findHexagonalPrism method sees whether or not the object the user enters is in the list of objects. I'm pretty sure the issue revolves around the bit "myHexList.get(label)"


Any input is appreciated.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jack, welcome to the Ranch!

It seems that you have a problem, but from what you posted I can't really tell what it is. So could you expand on your post a bit? It would help if you told what you expected to happen and what happened instead. Copying and pasting of things which appear in your console are preferable to paraphrases of what you see there, and generally detail is better than hand-waving.

For more detail have a look at our FAQ pageHow To Ask Questions On Java Ranch.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

It looks like you're trying to look up an object based on some information. The appropriate date type for that is a Map, not a List.

Take a look at java.util.Map and its go-to implementation, java.util.HashMap.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!