Initializing a boolean array to false

前端 未结 2 1318
后悔当初
后悔当初 2021-02-02 08:20

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

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 09:15

    A boolean is initialized to false by default. So you need not to do anything specific here. When you create an array of booleans and don't initialize it all the elements will be be false.

    how do I initialize it to True then?

    Simple Arrays.fill(array, Boolean.TRUE);

提交回复
热议问题