0

I have this array:

Integer[] originalItems = itemsArray.stream()
            .distinct()
            .sorted()
            .toArray(Integer[]::new);

I would like to return it as int[] rather than as Integer[].

I have tried to call .toArray(int[]::new) but I get this error:

no instance(s) of type variable(s) A exist so that int[] conforms to A[]

0

1 Answer 1

6
.mapToInt(Integer::intValue).toArray();

instead of

.toArray(Integer[]::new);

because

<A> A[] toArray(IntFunction<A[]> generator);

doesn't work with primitive types.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.