We create a new list: List<Integer> result = new ArrayList<Integer>(); Finally we convert it to int array and return this array: return result.stream().mapToInt(i -> i).toArray();
List in Java
List Interface in Java with Examples The List interface provides a way to store the ordered collection. It is a child interface of Collection. It is an ordered collection of objects in which duplicate values can be stored. Since List preserves the insertion order, it allows positional access and insertion of elements. List<Integer> l1 = …