Say we have a Draw object:
class Draw {
private int num1, num2, num3;
public Draw (int num1, int num2, int num3) {
this.num1 = num1;
this.num2 = num2;
this.num3 = num3;
}
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = num1;
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = num2;
}
public int getNum3() {
return num3;
}
public void setNum3(int num3) {
this.num3 = num3;
}
public List<Integer> getResultAsList() {
return Arrays.asList(num1, num2, num3);
}
}
Now, having a Draws list, I need to get a map, where the key is the number in the draw and the value is the number (how many times this number was drawn)
For example, having
List<Draw> drawList = Arrays.asList(new Draw(1,2,5), new Draw(1,5,6));
I want to get the following card: {1 = 2, 2 = 1, 5 = 2, 6 = 1}
Is it possible to implement this with new groupingBy java 8 operations or another new function?
Thank.
source
share