I am trying to store a tempList in bigList but after using clear nothing is getting stored.
So what i am trying to do is store a list of list inside bigList, but after storing the tempList in bigList I want to populate new data in tempList and again store it in biglist.
import java.util.ArrayList;
import java.util.List;
public class Demo {
public static void main(String [] args){
List<List<String>> bigList = new ArrayList<>();
List<String> tempList = new ArrayList<>();
List<String> list2 = new ArrayList<>();
list2.add("2");
List<String> list3 = new ArrayList<>();
list3.add("3");
tempList.addAll(list2);
bigList.add(tempList);
tempList.clear();
tempList.addAll(list3);
bigList.add(tempList);
tempList.clear();
for(int i=0;i<bigList.size() && !bigList.isEmpty();i++){
if(!bigList.get(i).isEmpty())
System.out.println(bigList.get(i).get(0));
}
}
}