I'm trying to access an element inside an array, which is inside an ArrayList. For example, lets say:
ArrayList list = new ArrayList();
int[] x = new int[2];
x[0] = 2;
x[1] = 3;
list.add(x);
So, later on lets say i'd like to print x[1]
, I've tried doing this:
System.out.println(list.get(0)[1]);
But this gives me: Solution.java:47: error: incompatible types: Object cannot be converted to int[]
I tried to store the array in another array and access the new array but this gives the same error message.
I'm relatively new to java and moving from JavaScript where variables aren't nearly strict. I'm not extremely familiar with collections, I found this answer here:
But as you can see, this solution is not working for me. If there is anything i'm neglecting or overlooking - I would greatly appreciate any advice. Thank you.
EDIT: This question isn't weather or not I should use raw data types - though I will make sure to review this more in the future - raw data types are being used and the question is how to access them.