How To Removed Elements From The Array At Random?

  • Please we urge all unregistered users to swiftly register to enable you enjoy loads of benefits rollingout in our community. Be open to opportunities to do good for someone else today. Anything that do not please God in your life has come to distroy you.

AdServersite

Member
Nov 24, 2023
193
0
16
33
Abuja Nigeria

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).
 

BSF For Soul Wining Support Donation

Total amount
$0.00
Goal
$1,000.00
Donation ends: