initialize java array vs other initialization?

后端 未结 5 1136
太阳男子
太阳男子 2021-01-28 05:05

I know that when I initialize a char array: I have to

char[] b= new char[5];

or

char[] b= new char[5]({1,2,3,4,5});
         


        
5条回答
  •  无人及你
    2021-01-28 05:39

    Arrays and ArrayList are used for different purposes. If you need a fixed size collection of objects then go for array but if you need dynamically growing collection of objects then go for arraylist. In some way compiler need to know about what is your need, hence the syntax is different.

提交回复
热议问题