Package Test;import Java.util.arraylist;import java.util.arrays;import java.util.list;import java.util.Random; public class Createarraylist {public static void main (string[] args) {list<integer> NewList = Create (10); System.out.println (Arrays.tostring (Newlist.toarray ())); list<integer> deletelist = delete (newlist,5); System.out.println (Arrays.tostring (Deletelist.toarray ()));} public static list<integer> Create (int size) {Random r = new Random (); list<integer> list = new arraylist<> (), for (int i=0;i<size;i++) {int temp = r.nextint (size); List.add (temp );} return list;} public static list<integer> Delete (list<integer> needlist,int flagindex) {for (int i=0;i<needlist.size ( );) {if (Needlist.get (i). Intvalue () <flagindex) {needlist.remove (i); i=0;} else {i++;}} return needlist;}}
The program creates a ArrayList, adds 10 random numbers from 1 to 10, deletes a number greater than 5 Java