How to convert ArrayList<Integer> to an int[]?

array that is saved in the strings.xml and I what to get how many items is there in the list, then put it in another list. For example if the String contains {"One", "Two", "Three"} then I want an int that contains {0,1,2} and the only way to do it is to use the ArrayList so I could use the add method.

Here is the code I’m using to make this:

String[] names;
ArrayList<Integer> MyList;

for (int i = 0; i < names.length; i++){
  MyList.add(i);
}

but the problem is that I don’t know how to change the ArrayList into an int[]. How can this be done?


Source: android

Leave a Reply