Initializing a boolean array to 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); 回答1: The default value for the elements in a boolean[] is false. You don't need to do anything. The reason it's necessary for Boolean[] is because the default value is null . To initialize to true, use the overload of Arrays.fill that accepts a boolean[] .