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

Moving from Python to Java - list question

 
Joee Little
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My favourite language at this point is python, but the recent work on java 6 has been getting me a bit interested in shifting focus. So far, I've been pretty happy with the language, except for one thing that's been driving me crazy today.

In python one can easily put together a list of different primitives or strings, such as this, which contains both integers and strings.

PhoneBook = {
{"Smith", "Bob", "2566 fakestreet", 5555555555, 48917},
{"Smitty", "John", "9866 fakestreet", 5554855555, 48917},
{"Fakington", "Laura", "7666 fakestreet", 9873575555, 71517}
}

And from there do a simple match for values in each to find the rest of the values. Looking for a phone number of 5554855555 for example, which would also give the correct position in the list for the name and address associated with it.


I'm a bit lost as to how this could be done in java. There seems to be an overwhelming amount of collections, but none of them seem to match what I'm looking for here.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way would be to create a Map and encapsulate the values in a class definition. You could then use one of the fields of the class definition as the key, and the object as the value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic