I have a decision to make. I want to write a list of names and directions. Its very small list and i dont want to access it outside of the class.
I have 2 options to store the elements dynamically: 1. A nested linkedlist 2. An small class whith开发者_开发问答 two members, and add this element to a single Linkedlist.
Which one is the right approach?
Thanks a lot, David.
Make an inner class - the code will be easier to read.
List<List<String>> list = ..;
String name = list.get(0).get(0);
is less readable than:
List<Location> list = ..;
String name = list.get(0).getName();
Another option is to use a Map<String, String>
where the key is the name, and the value - the location. That's in case your normal usage involves looking up a location based on name. If both operations are regular, you can check BiMap
from guava libraries.
精彩评论