Java List to Long Number Array toLongArray(final List list)

Here you can find the source of toLongArray(final List list)

Description

to Long Array

License

LGPL

Declaration

public static long[] toLongArray(final List<Long> list) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.util.*;

public class Main {
    public static long[] toLongArray(final List<Long> list) {
        long[] array = new long[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);/* ww  w.j  av a2s  . com*/
        }
        return array;
    }

    public static int size(final Object[] array) {
        return null != array ? array.length : 0;
    }

    public static int size(final Collection collection) {
        return null != collection ? collection.size() : 0;
    }

    public static int size(final Map map) {
        return null != map ? map.size() : 0;
    }

    public static <T> T get(T[] array, int index) {
        if (array.length < index + 1) {
            return null;
        }
        return array[index];
    }

    public static <T> T get(final T[] array, final int index, final T defaultValue) {
        if (array.length < index + 1) {
            return defaultValue;
        }
        final T result = array[index];
        return null != result ? result : defaultValue; // array[index];
    }

    public static <T> T get(final Collection<T> collection, final int index) {
        if (collection.size() < index + 1) {
            return null;
        }
        int i = 0;
        for (T item : collection) {
            if (i == index) {
                return item;
            }
            i++;
        }
        return null;
    }
}

Related

  1. toLong(List list)
  2. toLongArray(final List idList)
  3. toLongArray(List list)
  4. toLongArray(List list)
  5. toLongArray(List list)