This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java List" Watch "Java List" New topic
Author

Java List

Eshwar Prasad
Ranch Hand

Joined: Mar 21, 2008
Posts: 202
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
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
That looks like a candidate for Maps. The Jakarta Commons people have a bi-directional Map.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java List
 
Similar Threads
Collections.copy()
Inner class
Question about Collections.sort()
Equivalent of logic iterate in Struts 2
I want to check previous (value) of HashMap before adding the current key?