I kept getting error message 'Out Of Bounds Exception: Index: 5000, Size: 5000'. So I tried compiling the same code in IntelliJ, and it worked fine. It seems like the CodeGym mini-version of Java limits the number of items that can be added to an list to 5000. Does anyone know if this is correct? Thanks and happy coding!
package com.codegym.task.task08.task0808;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Iterator;
/*
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) {
for (int i = 0; i < 10000; i++) {
list.add(i);
}
}
public static void get10000(List list) {
for (int i = 0 ; i < 10000; i++) {
list.get(i);
}
}
public static void set10000(List list) {
for (int i = 0; i < 10000; i++) {
list.set(i, i);
}
}
public static void remove10000(List list) {
for (int i = 0; i < 5001; i++) {
list.remove(i);
}
}
}