assassinsweed1 assassinsweed1 - 10 months ago 60
Java Question

Converting ArrayList<Integer> into int[] won't work in Java

I have been developing a program where I have to convert an ArrayList into an int[]. I do not get any syntax errors when I run the code. However, when I print the int[] to see if it does work, it prints out a random string which is "[I@2a139a55" How can I fix this?

I cannot use an int[] from the start. This program HAS to convert an ArrayList into int[].

ArrayList<Integer> student_id = new ArrayList<Integer>();

int[] student_id_array = new int[student_id.size()];
for (int i=0, len = student_id.size(); i < len; i ++){
student_id_array[i] = student_id.get(i);

Answer Source

You are printing out the reference to the array. Use Arrays.toString(int[]).