I have a list of lists in Java which has 3 lists of integers in it.
List<List<Integer>> L;
myList = new ArrayList<>();
for(int i=0; i<3; i++){
myList.add(new ArrayList<Integer>());
}
myList.get(0).add(1);
myList.get(0).add(2);
myList.get(0).add(3);
myList.get(0).add(4);
myList.get(1).add(1);
myList.get(1).add(2);
.
.
.
My problem is that the number of the items that can be added to each of lists is unlimited in my code, but I want to limit the number of the items that each list can get. For example, each list can get only 4 items and when the 5th item is received by one of these lists, I need a shift to the left so the 5th item can be added to the list. Here is an example of what I intend to do:
At first: myList = [[1,2,3,4],[1,2,3,4],[1,2,3,4]]
After the 5th item is added to the first list of myList: myList = [[2,3,4,5],[1,2,3,4],[1,2,3,4]]
I tried to limit the number by something like this:
for(int i=0; i<3; i++){
myList.add(new ArrayList<Integer>(4));
}
but it didn't work. How can I do this?