Any shortcut to initialize all array elements to zero?

后端 未结 14 2788
北恋
北恋 2020-11-28 18:12

In C/C++ I used to do

int arr[10] = {0};

...to initialize all my array elements to 0.

Is there a similar shortcut in

14条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 18:49

    declare the array as instance variable in the class i.e. out of every method and JVM will give it 0 as default value. You need not to worry anymore

提交回复
热议问题