/**
* Randomly remove a number of elements from an array to form a new array
* @param array of arrays of a string type
* @param number of elements to be removed
* @return a random array
* @throws NullPointerException The original array cannot be empty
* @throws arrayindexoutofboundsexception new array length should not be greater than the length of the original array
*/
public static string[] Getrandomarray (string[] array, int number)
Throws NullPointerException, ArrayIndexOutOfBoundsException {
Random random = new random ();
string[] Arraynew = new string[number];//The newly obtained array
String[] arraytemp = array in array;//change, first equals original array
int index;//array array subscript in the definition change
for (int i = 0; i < arraynew.length; i++) {
index = Random.nextint (arraytemp.length); randomly get an array subscript
Arraynew[i] = arraytemp[index];//Copy to get new array
Arraytemp = copyexcept (arraytemp, index);}
return arraynew;}
}
return arraynew;
}
Randomly remove a number of elements from an array to form a new array