Q:

Create a sublist of fixed size from a list and if the elements are less add zeros to complete the sublist

I am new to Java 8 and trying the implement creating partitions of fixed size of 5 elements from a list.
If the list is short of elements then i need to add zeros to it.
For example: If the original list has below elements:
[1,2,3,4,5,6,7]
The sublist will be as below:
[1,2,3,4,5],[6,7,0,0,0]
So far, i found the below method.
Can someone please help me with changing this to add zeros if a sublist is less than 5?
public static <T> List<List<T>> splitLists(List<T> alist, final int len) {
    return IntStream.range(0, alist.size()) 
            .filter(i -> i % len == 0) 
            .boxed() 
            .map(i -> alist.subList(i, Math.min(i + len, alist.size()))) 
            .collect(Collectors.toList()); 
}

Also, i need to pass a list of BigDecimal to this method,but want to keep this a generic list only so that i can reuse this method in other scenarios as well.
List<BigDecimal> l = new ArrayList<>();
l.add(new BigDecimal(1));
l.add(new BigDecimal(2));
l.add(new BigDecimal(3));
l.add(new BigDecimal(4));
l.add(new BigDecimal(5));
l.add(new BigDecimal(6));
l.add(new BigDecimal(7));
List<List<BigDecimal>> findPattern = splitLists(l,5);

A:

Changing the question after answers were postet is a bad habit. However, BigDecimal, here we go:
import java.math.BigDecimal

List<BigDecimal> l = new ArrayList<>();
l.add(new BigDecimal(1));
l.add(new BigDecimal(2));
l.add(new BigDecimal(3));
l.add(new BigDecimal(4));
l.add(new BigDecimal(5));
l.add(new BigDecimal(6));
l.add(new BigDecimal(7));

List<List<BigDecimal>> findPattern = splitLists(l, 5, new BigDecimal (0));

We calculate the length mismatch and add a neutral element. Of course we need to get one of type T:
    int mismatch = len - (alist.size () % len);
    for (int i = 0; i < mismatch; ++i) 
         alist.add (neutral);

public static <T> List<List<T>> splitLists (final List<T> alist, final int len, T neutral) {
    int mismatch = len - (alist.size () % len);
    for (int i = 0; i < mismatch; ++i) alist.add (neutral) ;
    return IntStream.range(0, alist.size()) 
            .filter(i -> i % len == 0) 
            .boxed() 
            .map(i -> alist.subList(i, Math.min(i + len, alist.size()))) 
            .collect(Collectors.toList()); 
}

Call to that list expects one more parameter, the neutral element:
-> List<List<BigDecimal>> findPattern = splitLists(l, 5, new BigDecimal (0));
|  Modified variable findPattern of type List<List<BigDecimal>> with initial value [[1, 2, 3, 4, 5], [6, 7, 0, 0, 0]]
|    Update overwrote variable findPattern

(Testet in jshell, if you wonder about the fancy output.)
If you need your old List untouched, either pass a copy or create a copy in the method to work on. 

