arraylist - Overload addAll function in Java -
this question has reply here:
what best way filter java collection? 23 answersi wanted convert array[] arraylist. in java simpler use
new arraylist<element>(arrays.aslist(array))
but if wanted sanity check on elements in array before putting them in arraylist. e.g.
new arraylist<element>(arrays.aslist(array,sanity.isnotnull))
i.e. similar comparator, add together element in arraylist when function in sec argument true element.
i for , add together elements myself, there inbuilt in java? sec question: there way overload addall function accomplish above mentioned goal?
in java 8 can like:
new arraylist<element>(arrays.aslist(array).stream() .filter(elem -> /* status on element returns boolean, i.e. "elem.age > 21" */ ) ).collect(collectors.tolist());
java arraylist
No comments:
Post a Comment