Java:有没有一种方法可以将ArrayList<Boolean>转换为Boolean[](基本数组)? 1 年,1 月 Questions & Answers 307 我知道可以通过迭代元素来完成,但是有没有预定义的方法或方法来使用map
# 1 楼答案 阿帕奇ArrayUtils.toPrimitive public static boolean[] toPrimitive(Boolean[] array, boolean valueForNull) Converts an array of object Booleans to primitives handling null. This method returns null for a null input array. 但是,此方法需要一个布尔数组,因此首先需要使用toArray将列表转换为数组 ArrayUtils.toPrimitive(list.toArray(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY)); 您需要下载ApacheCommonsLang库 https://commons.apache.org/proper/commons-lang/download_lang.cgi
# 1 楼答案
阿帕奇ArrayUtils.toPrimitive
但是,此方法需要一个布尔数组,因此首先需要使用
toArray
将列表转换为数组您需要下载ApacheCommonsLang库
https://commons.apache.org/proper/commons-lang/download_lang.cgi