Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java List

 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48394
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks like a candidate for Maps. The Jakarta Commons people have a bi-directional Map.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic