JAVA: SomeStructure<E> to make it sorted by another type T? <p>I have a data class as following:</p> <pre><code>class MyData { private UUID id; private String data1; private String data2} </code></pre> <p>I store its instance in a map:</p> <pre><code>private Map&lt;UUID, MyData&gt; myData; </code></pre> <p>As all we know, I can get MyData instance by UUID:</p> <pre><code>MyData instance = myData.get(UUID); </code></pre> <p>But I also need to get MyData instance by index. What's more, the index is sorted by, say, MyData.data1 field. So I need a new data structure to store UUID according to index order, perhaps something like this:</p> <pre><code>private SomeStructure&lt;UUID&gt; myDataIndex; </code></pre> <p>What I want is this <code>SomeStructure</code> class. It should have a public method such as:</p> <pre><code>public UUID getUuidByIndex(int index); </code></pre> <p>And, it should sort UUID elements by MyData.data1 field.</p> <p>And, every time I put an item to <code>private Map&lt;UUID, MyData&gt; myData</code>, the item's UUID is also added to <code>private SomeStructure&lt;UUID&gt; myDataIndex</code>. I think this is a performance consideration, not generating an ArrayList or something else when I get element by index.</p> <p>Any ideas about this <code>SomeStructure</code>? I would appreciate more about a method that extends or implements known JAVA data structure. Of course, fully customized structure is also highly appreciated.</p> <p>To make you fully understand my question, I'd like to state my situation:</p> <ol> <li><p>why I have Map? I wanna get data by UUID.</p></li> <li><p>why I want SomeStructure? I wanna get data by index either.</p></li> </ol> <p>To make it simple: I want iterate my data through two different ways.</p> <p>Many thanks!</p>