In Java, I found some tutorials online, and they teach differently when it comes to arrays,
Example 1:
Create an array object using the "new" keyword, and then assign values to it.
int[] values;
values = new int[5];
values [0] = 10;
values [1] = 20;
values [2] = 30;
values [3] = 40;
values [4] = 50;
System.out.println (values[2]); //Output : 30
Example 2:
Use curly braces to assign values to an array.
int[] values = {34,45,62,72}
System.out.println (values [2]);
What is the difference between the two examples?
source
share