Java Solution || Sorting || Easy & Clean Code
java\nclass Solution {\n    public int maxStarSum(int[] vals, int[][] edges, int k) {\n        ArrayList<Integer>[] a = new ArrayList[vals.length];\n        \n 
```java\nclass Solution {\n    public int maxStarSum(int[] vals, int[][] edges, int k) {\n        ArrayList<Integer>[] a = new ArrayList[vals.length];\n        \n        for(int i=0;i<vals.length;i++)\n        {\n            a[i] = new ArrayList<Integer>();\n        }\n        \n        for(int[] x:edges)\n        {\n            if(vals[x[1]]>0)\n            a[x[0]].add(vals[x[1]]);\n            if(vals[x[0]]>0)\n            a[x[1]].add(vals[x[0]]);\n        }\n        \n        int max=Integer.MIN_VALUE;\n        int j=0;\n        for(ArrayList<Integer> list: a){\n            Collections.sort(list,Collections.reverseOrder());\n            int sum=vals[j++];\n            for(int i=0;i<Math.min(list.size(),k);i++)\n            {\n                sum+=list.get(i);\n            }\n            max=Math.max(sum,max);\n        }\n        return max;\n    }\n}\n```
['Sorting', 'Java']