Apply grouping criteria to your results.
To group your results according to specific attributes, use the Query.groupBy(String groupByItem) method. For example, to group your results by ID and name, use:
String groupByItem = ("c.id, c.name");
Query query1 = new Query();
//other code for query1
query1.groupBy(groupByItem);