Reputation: 325
I am trying to select a random value from an Array but I don't know how can I remove it, function is properly generating random numbers from Array.
Help me Please that How can I remove selected number from my randomNumbers
Array
This is My code
static int[] randomNumbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
public static int randomArray(){
java.util.Random rand = new java.util.Random();
int first = randomNumbers[rand.nextInt(randomNumbers.length)];
return first;
}
Upvotes: 0
Views: 539
Reputation: 1378
No you cannot delete anything from an array.
Arrays are of fixed size in java. You can use ArrayList<Int>
for your purpose.
Upvotes: 3