Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A linked hashmap doesn't work as a list because it's just a regular map where the order with which the nodes were added is kept, for you to use later (with an iterator for example). That's why you don't have any function to add an element with an index.</p> <p>If you want to add an element to the beggining of a <code>LinkedHashMultimap</code> you will need to create a new one and add all elements of the old <code>LinkedHashMultimap</code> to the new one:</p> <pre><code>Multimap&lt;Integer, String&gt; newMap = LinkedHashMultimap.create(); newMap.put(key,valueForTheFirstIndex); // first (and only) object of new map newMap.putAll(commandMap); // adds with the order of commandMap commandMap = newMap; </code></pre> <p>the add all will add all other elements to the newMap making that <code>valueForTheFirstIndex</code> actually stay in the first index. Note that you are loosing the advantages of using a map if you do this, because if always add to the begining of the array your complexity will be O(n^2). If you want to add to indexes you should use a list while you are adding stuff and then convert to a linkedhashmap for fast accessing.</p> <hr> <p>(out of question scope)</p> <p>The value that you have there named <code>index</code> is not an index but is actually a key. You don't have indexes in maps.</p> <pre><code>actionMap.put(index, "string"); </code></pre> <p>As you can read in the documentation: <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/LinkedHashMultimap.html" rel="nofollow">http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/LinkedHashMultimap.html</a></p> <pre><code>put(K key, V value) // you don't see any reference to index there </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload