简体   繁体   中英

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

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?

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM