Any shortcut to initialize all array elements to zero?

后端 未结 14 2733
北恋
北恋 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:35

    If you are using Float or Integer then you can assign default value like this ...

    Integer[] data = new Integer[20];
    Arrays.fill(data,new Integer(0));
    

提交回复
热议问题