public static <T> List<T> decode(List<Object> encoded) {
        return encoded.stream().flatMap(e -> {
            if (e instanceof SimpleEntry) {
                SimpleEntry<Integer, T> entry = (SimpleEntry<Integer, T>) e;
                return Collections.nCopies(entry.getKey(), entry.getValue()).stream();
            }
            return Stream.of((T) e);
        }).collect(toList());
    }
<b>(**) Decode a run-length encoded list.</b>
<pre>
    decode(Arrays.asList((4, "a"), "b", (2, "c"), (2, "a"), "d", (4, "e")))
</pre>
java8/src/main/java/com/shekhargulati/ninetynine_problems/_01_lists/P12.java