File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Moving from Python to Java - list question" Watch "Moving from Python to Java - list question" New topic
Author

Moving from Python to Java - list question

Joee Little
Greenhorn

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: 2367
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Moving from Python to Java - list question
 
Similar Threads
Logic or syntax
HashMap implementation for an interpreter: cannot find symbol error
can a job in perl help me in my future java goals
Beginner Java frustrations from a Perl Programmer
Python as a first language