to Primitive Long Array from Collection<Long> - Android java.util

Android examples for java.util:Collection

Description

to Primitive Long Array from Collection<Long>

Demo Code


//package com.java2s;
import java.util.Collection;

public class Main {
    public static long[] toPrimitiveLongArray(Collection<Long> collection) {
        // Need to do this manually because we're converting to a primitive long array, not
        // a Long array.
        final int size = collection.size();
        final long[] ret = new long[size];
        // Collection doesn't have get(i).  (Iterable doesn't have size())
        int i = 0;
        for (Long value : collection) {
            ret[i++] = value;/*  w  ww . j  av a  2s . c om*/
        }
        return ret;
    }
}

Related Tutorials