title: how to get the required result, the result is array list?
body: <p>I have an array of object, which is basically an Arraylist.
  The input and output data look like this</p>
  
  <pre><code> data=  [
        {
          id:1,
          parent:0
        },
         {
          id:2,
          parent:0
        },
  
         {
          id:3,
          parent:1
        },
         {
          id:4,
          parent:1
        },
         {
          id:5,
          parent:3
        },
         {
          id:6,
          parent:3
        }
      ]
  </code></pre>
  
  <p>if parent of any object is equal to id, then that will become the children the result should look like this.</p>
  
  <pre><code>    [
        {
          id:1,
          parent:0,
          children:[
                    {
                      id:3,
                      parent:1,
                      children:[ {
                                  id:5,
                                  parent:3
                                 },
                                 {
                                  id:6,
                                  parent:3
                                  }
                                ]
                      },
                     {
                      id:4,
                      parent:1
                    }
            ]
        },
         {
          id:2,
          parent:0
        }
  
      ]
  </code></pre>
  
  <p>Because i am not able to access the inner element of the array of object by using for loop, i am not able to put condition on it.
  i try using something like this</p>
  
  <pre><code>for(Map &lt;String,Object&gt; individual_object: data) {
  
  }
  </code></pre>
  
  <p>How to do this?</p>
  
  <p>My complete code:</p>
  
  <pre><code>try {
              taxonDao.openCurrentSession();
              List&lt;Object[]&gt; taxonList = taxonDao.list(parent, classificationId, taxonIds, expand_taxon);
              List res = new ArrayList();
  
              Map&lt;String, Object&gt; m1 = new HashMap&lt;String, Object&gt;();
              TaxonUI ui = new TaxonUI();
              Map&lt;Long, Map&lt;String, Object&gt;&gt; m2 = new HashMap&lt;Long, Map&lt;String, Object&gt;&gt;();
              for (Object[] t : taxonList) {
                  Map&lt;String, Object&gt; m = new HashMap&lt;String, Object&gt;();
                  ui.setId((Long) t[0]);
                  ui.setTaxonid((Long) t[0]);
                  ui.setClassification((Long) t[4]);
                  ui.setPath((String) t[3]);
                  ui.setText((String) t[1]);
                  ui.setRank((Integer) t[2]);
                  if(t[5]!=null){
                      ui.setParent((Long)t[5]);
                  }
                  m.put("id", ui.getId());
                  m.put("taxonid", ui.getId());
                  m.put("text", ui.getText());
                  m.put("rank", ui.getRank());
                  m.put("path", ui.getPath());
                  m.put("classification", ui.getClassification());
                  m.put("parent", ui.getParent());
                  res.add(m);
              }
  
              return res;
          } catch (Exception e) {
              throw e;
          } finally {
              taxonDao.closeCurrentSession();
          }
  </code></pre>