Choosing random strings from an array in Java



Using ten random numbers placed in an array, I want to pick ten random strings from another array, but I'm getting ArrayIndexOutOfBoundsException.



int[] RandomArray = new int[10]; // this is an array of random numbers between 0 and 21

String[] StringArray = new String[22]; //This array has 22 diffrent sentences and gets them from the string.xml

String[] ResultStringArray = new String[10]; //This array shall have now the 10 randomly picked sentences

for (int i = 0; i < ResultStringArray.length; i++) {
ResultStringArray[i] = StringArray[ResultArray[i]];
}


What is the problem with the provided code?


No comments:

Post a Comment