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

后端 未结 5 713
感情败类
感情败类 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:24

    In order to do this, the best way would be to navigate through each array.

    For instance, going from Long[] to long[]:

    Long[] objLong = new Long[10];
    //fill objLong with some values
    long[] primLong = new long[objLong.length]
    
    for(int index = 0; index < objLong.length; index++)
    {
        primLong[index] = objLong[index];
    }
    

    Due to auto-unboxing, this should work out by converting Long to long.

提交回复
热议问题