File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Moving from Python to Java - list question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Moving from Python to Java - list question" Watch "Moving from Python to Java - list question" New topic

Moving from Python to Java - list question

Joee Little

Joined: May 14, 2006
Posts: 1
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

Joined: Feb 07, 2005
Posts: 2398
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.
I agree. Here's the link:
subject: Moving from Python to Java - list question
It's not a secret anymore!