I get "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space" exception while adding values in arrayList. This is just a example
public class Test {
public static void main(String[] args)
{
Test t= new Test();
ArrayList<ArrayList<String>> deleteError = new ArrayList<ArrayList<String>>();
for(TableItem item : items) // loop moves 800 times
{
for(String Element_ID : checkelementID) // another loop which check element ids which moves for 800 again
{
t.deleteErrorInArrayList("1", "GEN_err", "11", deleteError);
t.deleteErrorInArrayList("1", "Greater_than", "11", deleteError);
t.deleteErrorInArrayList("1", "GEN_err", "16", deleteError);
t.deleteErrorInArrayList("1", "Greater_than", "16", deleteError);
}
}
}
public void deleteErrorInArrayList(String rowID,String message,String column,ArrayList<ArrayList<String>> mainlist)
{
ArrayList<String> list = new ArrayList<String>();
list.add(rowID);
list.add(message);
list.add(column);
mainlist.add(list);
list = null;
}
}
Please help me. How to optimize above code so i can reduce time and remove exception.