Difference in Array initialization

后端 未结 5 1056
故里飘歌
故里飘歌 2021-01-20 23:40

While looking over a source file, i saw two ways of array initialization. I wonder is there a difference between

int[] value = new int[0];

and<

5条回答
  •  北海茫月
    2021-01-21 00:38

    Actually there is no difference. It's Syntactic sugar in java array declaration.

    The first type declaration is less confusing, at least for me :).

    Note: I'm not sure why you given the length as zero while declaring.

    If possible, go through https://stackoverflow.com/a/19558179/1927832 for some advantages over another.

提交回复
热议问题