Collecting the result of cypher query into a hash map java?
<p>This is a followup of  <a href="https://stackoverflow.com/questions/34677104/neo4j-cypher-match-in-java-find-connected-nodes">Finding connected nodes</a> question. </p>

<p>The code is </p>

<pre><code>    firstNode = graphDb.createNode();//creating nodes
    firstNode.setProperty( "person", "Andy " ); 
    Label myLabel = DynamicLabel.label("person");
    firstNode.addLabel(myLabel); ...

    relationship = firstNode.createRelationshipTo( secondNode, RelTypes.emails );// creating relationships
    relationship.setProperty( "relationship", "email " );....


    ExecutionEngine engine = new ExecutionEngine(graphDb);
        ExecutionResult result = engine.execute("MATCH (sender:person)-[:emails]- (receiver)RETURN sender,  count(receiver)as count, collect(receiver) as receivers ORDER BY count DESC ");
        System.out.println(result.dumpToString());
</code></pre>

<p>The result I got was:</p>

<pre><code> sender                  | count | receivers                                                                 
Node[2]{person:"Chris"} | 3     | [Node[4]{person:"Elsa "},Node[0]{person:"Andy "},Node[1]{person:"Bobby"}] 
Node[4]{person:"Elsa "} | 3     | [Node[5]{person:"Frank"},Node[2]{person:"Chris"},Node[3]{person:"David"}]
Node[1]{person:"Bobby"} | 3     | [Node[2]{person:"Chris"},Node[3]{person:"David"},Node[0]{person:"Andy "}]
Node[5]{person:"Frank"} | 2     | [Node[3]{person:"David"},Node[4]{person:"Elsa "}
</code></pre>

<p>How to collect the sender as key and receivers as values? 
For ex : <code>{Frank =[David, Elsa],  Chris =[Elsa, Andy, Nobby]..</code> </p>

<p>Any idea? </p>

<p>Initially I tried  iterating something like this</p>

<pre><code>        for (Map&lt;String,Object&gt; row : result) {
               Node x = (Node)row.get("receivers");
               System.out.println(x);

               for (String prop : x.getPropertyKeys()) {
                  System.out.println(prop +": "+x.getProperty(prop));

               }
</code></pre>

<p>This throws classcast exception. It works for column "sender" and not for "receivers".</p>

<p>I am very new to cypher. I don't know how to transform the result into a hash map. How is this possible ?</p>