The requirements for get and set are not approved, while insert and remove are accepted. Can't see why, they are based on the same loop...
public static void get10000(List list) {
//write your code here
Random rand = new Random();
for (int i=0; i<10000; i++) {
int n = rand.nextInt(list.size());
list.get(n);
}
}
public static void set10000(List list) {
//write your code here
Random rand = new Random();
for (int i=0; i<10000; i++) {
int n = rand.nextInt(list.size());
list.set(n, "set");
}
}
package com.codegym.task.task08.task0808;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
/*
10 thousand deletions and insertions
*/
public class Solution {
public static void main(String[] args) throws Exception {
// ArrayList
ArrayList arrayList = new ArrayList();
insert10000(arrayList);
get10000(arrayList);
set10000(arrayList);
remove10000(arrayList);
// LinkedList
LinkedList linkedList = new LinkedList();
insert10000(linkedList);
get10000(linkedList);
set10000(linkedList);
remove10000(linkedList);
}
public static void insert10000(List list) {
//write your code here
Random rand = new Random();
for (int i=0; i<10000; i++) {
int n = 0;
if (list.size()>0)
n = rand.nextInt(list.size());
list.add(n,"insert");
}
}
public static void get10000(List list) {
//write your code here
Random rand = new Random();
for (int i=0; i<10000; i++) {
int n = rand.nextInt(list.size());
list.get(n);
}
}
public static void set10000(List list) {
//write your code here
Random rand = new Random();
for (int i=0; i<10000; i++) {
int n = rand.nextInt(list.size());
list.set(n, "set");
}
}
public static void remove10000(List list) {
//write your code here
Random rand = new Random();
for (int i=0; i<10000; i++) {
int n = rand.nextInt(list.size());
list.remove(n);
}
}
}