public static <T> List<T> flatten(List<?> list, Class<T> elementType) {
        List<T> flatten = new ArrayList<>();
        list.forEach(e -> {
            if (e instanceof List) {
                flatten.addAll(flatten((List<?>) e, elementType));
            } else {
                flatten.add((T) e);
            }
        });
        return flatten;
    }
<b>(**) Flatten a nested list structure</b>
<p>
Transform a list, possibly holding lists as elements into a 'flat' list by replacing each list with its elements (recursively).
</p>
java8/src/main/java/com/shekhargulati/ninetynine_problems/_01_lists/P07.java