How to get submap of LinkedHashMap by element index?
<p>I am trying to get a submap of <code>LinkedHashMap</code> based on element index. Am I reinventing the wheel here? Sounds like this should be somewhere in API already:</p>

<pre><code>public &lt;K,V&gt; LinkedHashMap&lt;K,V&gt; subMap(LinkedHashMap&lt;K,V&gt; map, int fromIndex, int toIndex) {
    LinkedHashMap&lt;K,V&gt; result = new LinkedHashMap&lt;K,V&gt;();

    int i=0;
    for(Map.Entry&lt;K,V&gt; entry : map.entrySet()) {
        if(i &gt;= fromIndex &amp;&amp; i &lt; toIndex) {
            result.put(entry.getKey(), entry.getValue());
        }
        i++;
    }

    return result;
}
</code></pre>

<p>Is this the way to go or there are some other better/existing solutions (within Java 6 API).</p>
