I have a list of Class1, which has a method isAvailable() which returns a boolean.
I am trying to create an array of boolean from this.
So far I have tried the below:
List<Class1> class1List;
boolean[] isAvailableArray = class1List.stream()
.map(e -> e.isAvailable())
.toArray();
However this is throwing a can't convert from Object[] to boolean[] error.
What is the reason for this.
Boolean[] isAvailableArray = class1List.stream().map(e -> e.isAvailable()).toArray(Boolean[]::new);boolean[]? It’s very likely that whatever you want to do with the boolean array afterwards, can be done directly or at least, with an alternative way not requiring the boolean array.