Android IDE (AIDE) Support Forum

Arrays initialize a with the array {57,3,9,} ineed help with this

public class Main
{
public static void main(String[] args)
{
int[] a = { 4, 8, 2 };
for (int i = 0; i < a.length; i++)
{
System.out.println(a[i]);
}
}
}

4,8,2 is not 57,3,9 :confused:

initialize or override?

initialize : the array has values 57,3,9 from the start
int[] a = { 57,3,9 };

override: the array change values

Option 1:
int[] a = { 4, 8, 2 };
a[0] = 57;
a[1] = 3;
a[2] = 9;

Option 2:
int[] a = { 4, 8, 2 }, b = { 57,3,9 };
System.arraycopy(a, 0, b, 0, 3);