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 Java List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java List" Watch "Java List" New topic

Java List

Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

There was a question asked in an interview.

There will be list having below elements as origin and destination.

origin | destination
AA | 01
AB | 02
AC | 03
AD | 04

If a user provide input as 04 then the out put should be AD. I was said to use getters and setters for this

As list would not have key value pair, i thought that i would take two lists. One for origin and one for destination.

As per my code, 04 is in 3rd position of destination list. Hence, I retrieved the third element from origin list. If i add new object after the third element still my program works. If i add before third element, the output would be different for sure.

My code for the program is as below.

Please let me know if i could do this program in different way to make it generalize
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
That looks like a candidate for Maps. The Jakarta Commons people have a bi-directional Map.
I agree. Here's the link:
subject: Java List
It's not a secret anymore!