Who has removed elements from the array at random?
I want to know how to remove each element of an array in Java at random, one by one. What I have written is the program shown below:
JavaScript:
//randomly remove elements from an array
import java.util.Random;
public class Main {
public static void main(String[] args) {
int size = 5;
Random r = new Random();
int result = r.nextInt(size);
String[] arr1 = {"1", "2", "3", "4", "5", "6"};
for (int i = 0; i < size; i++) {
arr1[i] = arr1[size];
}
System.out.println(arr1);
}
}
I need assistance with both the logic for deleting the elements and publishing the result to make sure it is empty (it might need to be a String).