Java difference between static arrays and non-static arrays

Difference:
1, the array created at different times, is a static definition of it is created, the dynamic is not created when you define, create only use, saving memory space in a sense.
2, the use of different scenarios, beginning that the length of the array used to initialize static, whereas dynamic initialization.

Static array can not meet the actual needs of our program, say I need to dynamically add the program is running to the array data, then our static array size is fixed, obviously you can not add data, the data must be dynamically added to use dynamic array, each element type dynamic array is consistent. It has a capacity scalability, and data synchronization operation efficiency and so!

 

Initialize a static array

String[] suit = new String[] { "spades", "hearts", "diamonds", "clubs" }; 

Or only

String[] suit = {
  "spades", "hearts", "diamonds", "clubs" }; 

Or as a List

List suit = Arrays.asList(
  "spades", "hearts", "diamonds", "clubs" );

Guess you like

Origin www.cnblogs.com/xiaoshen666/p/11327216.html