convert Long[] to long[] (primitive) java

后端 未结 5 731
感情败类
感情败类 2021-02-18 13:13

How do i convert Long[] to long[]? For example i know how to convert if it is not array as below.

long ll = (Long)Object[1].longValue()

But how

5条回答
  •  無奈伤痛
    2021-02-18 13:25

    using java 8 streams:

    public static long[] unboxed(final Long[] array) {
        return Arrays.stream(array)
                     .filter(Objects::nonNull)
                     .mapToLong(Long::longValue)
                     .toArray();
    }
    

提交回复
热议问题