Is it possible to bind with collection and if so how?

75 Views Asked by At

I have List<CheckBox>. I need to bind the selected property of them to a List<Boolean>. Is there any way to achieve it. If so how?

1

There are 1 best solutions below

0
miwoe On BEST ANSWER

In Java 8 you can loop to the list with a stream:

List<Boolean> booleans = 
    checkBoxList.stream().map(checkbox -> checkbox.isSelected()).collect(Collectors.toList());

Of course, this not binding. It will copy the value to the new lists. If you change the values in booleans, it won't in the original checkBoxList object. boolean and Boolean are both immutable.

Edit: Maybe your UI-Framework can handle List<.Checkbox> directly...