Ive got an ArrayList with String, int and double in it, a total of 20 elements.
Im trying to move the Strings to a String-array, the ints to an int-array and the doubles to a double-array. But I cant figure out how, this is what I have for fnding Integers:
private ArrayList <Object> randomList = new ArrayList <Object>();
private int [] intArray = new int[10];
public void example(){
createArray();
for(int i = 0; i<randomList.size();i++){
if(randomList.get(i)instanceof Integer){
intArray[i]= (Integer) randomList.get(i);
}
}
}
I cant understand why this dosnt work, it tries to add objects that arent Integers into my array causing an outOfBounds exception, since its trying to add more then 10 elements.