Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: Sorting a Map, Map<Long,Map<String, Data>> based on the inner map
    primarykey
    data
    text
    <p>I am new to java and is still in the learning phase. I have a structure </p> <pre><code>Map&lt;Long, Map&lt;String, Data&gt;&gt; mapData </code></pre> <p><code>Data</code> has 2 fields <code>time</code> and <code>distance</code> and the <code>Map</code> has a time which is a <code>Long</code> field and <code>map</code> with <code>Identifier</code> and <code>Data</code> the structure looks like this</p> <pre><code>{190001919 = {[1= [data1], 2=[data2], 3=[data3]}, 190001920={[1=[data4], 2=[data5], 3=[data6]}, 1900019121= {[1=[data7], 2=[data8], 3=[data9]}} </code></pre> <p>and then convert it into a map - <code>Map&lt;String,List&lt;Data&gt;&gt; mpData</code> with <code>idenifier</code> as <code>key</code> and <code>values</code> as the values where there the identifier was the same.</p> <p>like </p> <pre><code>{1= [data1,data4,data7], 2= [data2,data5,data8],3= [data3,data6,data9]} </code></pre> <p>Could some one please help me? Update: With the below code, I get</p> <pre><code>{1= [data7,data7,data7], 2= [data8,data8,data8],3= [data9,data9,data9]} </code></pre> <p>instead of </p> <pre><code> {1= [data1,data4,data7], 2= [data2,data5,data8],3= [data3,data6,data9]} </code></pre> <p>Code:</p> <pre><code>public static Map&lt;Long, Map&lt;String, Data&gt;&gt; listData; public static Map&lt;String, List&lt;Data&gt;&gt; mapData; public convertMapData(Map&lt;Long, Map&lt;String, Data&gt;&gt; array) { listData = new HashMap(); listData = array; mapData = new HashMap&lt;&gt;(); Iterator it = listData.entrySet().iterator(); while (it.hasNext()) { Map.Entry&lt;Long, Map&lt;String, Data&gt;&gt; pairs = (Map.Entry) it .next(); Long keyValue = pairs.getKey(); Map inter = pairs.getValue(); Iterator it2 = inter.entrySet().iterator(); while (it2.hasNext()) { Map.Entry&lt;String, Data&gt; pairs_2 = (Map.Entry) it2 .next(); String identifierK = pairs_2.getKey(); Data resultV = pairs_2.getValue(); if (!(mapData.containsKey(identifierK))) { mapData.put(identifierK, new ArrayList&lt;Data&gt;()); } mapData.get(identifierK).add(resultV); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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