Is it possible to map key to Multi Dimensional Array List. Some thing like following example..
Map<K,V>
Where K is key for list of alphabet and V is a multi dimensional array list or normal array list that stores list of word. Some thing like a application that reads a dictionary file. I want to see an example. Example can be anything related to Map and Multi Dimensional Array-list. Or is there any other efficient way to implement collection? I have never used such implementations so if there is already a thread related to mine QA please post the link.
It is more common to create an ArrayList of definite type such as Integer, Double, etc. But there is also a method to create ArrayLists that are capable of holding Objects of multiple Types. We will discuss how we can use the Object class to create an ArrayList. Object class is the root of the class hierarchy.
Approach: ArrayLists can be joined in Java with the help of Collection. addAll() method. This method is called by the destination ArrayList and the other ArrayList is passed as the parameter to this method. This method appends the second ArrayList to the end of the first ArrayList.
The ArrayList class implements a growable array of objects. ArrayList cannot hold primitive data types such as int, double, char, and long.
The ArrayList has O(n) performance for every search, so for n searches its performance is O(n^2). The HashMap has O(1) performance for every search (on average), so for n searches its performance will be O(n). While the HashMap will be slower at first and take more memory, it will be faster for large values of n.
You can always do Map<String, <List<String>>
. e.g.
Map<String, List<String>> multimap = new HashMap<String, List<String>>();
String key = "asdf";
List<String> values = Arrays.asList("foo", "bar");
multimap.put(key, values);
You can also use the Multimap<String, String>
interface in Google Guava - might be a better fit for your needs. It simplifies the coding somewhat -
Multimap<String, String> multimap = new ArrayListMultimap<String, String>();
String key = "asdf";
multimap.put(key, "foo");
multimap.put(key, "bar");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With