本文介绍了将布尔数组初始化为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我下面有这段代码.如何初始化每个元素= false?
I have this piece of code below. How do I initialize each element = false?
boolean[] seats = new boolean[10]我看到了类似的问题.但是,第二行对我来说没有意义(您能解释第二行吗?).
I saw a similar question. But, the second line didnt make sense to me (Can you explain the 2nd line?).
Boolean[] array = new Boolean[size]; Arrays.fill(array, Boolean.FALSE);推荐答案
boolean[]中元素的默认值为false.您无需执行任何操作.
The default value for the elements in a boolean[] is false. You don't need to do anything.
Boolean[]之所以必要是因为默认值是null.
The reason it's necessary for Boolean[] is because the default value is null.
要初始化为true,请使用Arrays.fill的20boolean%29>过载接受boolean[].
To initialize to true, use the overload of Arrays.fill that accepts a boolean[].
boolean[] seats = new boolean[10]; Arrays.fill(seats, true);查看它是否可以在线运行: ideone
See it working online: ideone
更多推荐
将布尔数组初始化为false
发布评论