We have below list object that contains map:

```
[
  {groupname="HR", username="101"},
  {groupname="Admin", username="101"}, 
  {groupname="local", username="102"}, 
  {groupname="local", username="101"}, 
  {groupname="HR", username="102"}, 
  {groupname="Finance", username="101"}
]

```

we want to convert in below format:

```
[
  {groupname=["HR","Admin","Finance","local"], username="101"},
  {groupname=["local","HR"], username="102"}
]

```

I tried with code

```
     for(Object map : list)
     {
         Map entyMap =(Map) map;
        String username1= (String)entyMap.get("username");
        System.out.println("username1 : " + username1 );
        //for(String userName: map.keySet()){
            for(Object map1 : list)
            {
                Map entyMap1 =(Map) map1;
             if (entyMap1.containsValue(username1))
             {
                groupList.add(entyMap1.get("groupname"));
                System.out.println(" grouplist: " + groupList );
             }
            } 
        //}
        Map newMap = new HashMap();
        newMap.put("username",username1);
        newMap.put("groupname",groupList);
         System.out.println(" newMap value: " + newMap );
         mapSet.add(newMap);
          System.out.println(" list Value : " + mapSet );
        groupList.clear();
     }

```

if anyone has any handy code?