Java Collection to Array toLongArray(Collection collection)

Here you can find the source of toLongArray(Collection collection)

Description

This method converts collection to Long Array.

License

BSD License

Parameter

Parameter Description
collection Collection to be convert.

Return

long array.

Declaration

public static Long[] toLongArray(Collection<Long> collection) 

Method Source Code

//package com.java2s;
/*L/*w  ww  .j a v  a 2 s .com*/
 * Copyright Washington University in St. Louis, SemanticBits, Persistent Systems, Krishagni.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/commons-module/LICENSE.txt for details.
 */

import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**
     * This method converts collection to Long Array.
     * @param collection Collection to be convert.
     * @return long array.
     */
    public static Long[] toLongArray(Collection<Long> collection) {

        Long[] obj = new Long[collection.size()];

        int index = 0;
        Iterator<Long> iterator = collection.iterator();
        while (iterator.hasNext()) {
            obj[index] = (Long) iterator.next();
            index++;
        }
        return obj;
    }
}

Related

  1. toIntArray(Collection values)
  2. toIntArray(final Collection c)
  3. toIntArray(final Collection col)
  4. toIntArray(final Collection collection)
  5. toIntArray(final Collection values)
  6. toLongArray(Collection collection)
  7. toStringArray(Collection collection)
  8. toStringArray(Collection collection)
  9. toStringArray(Collection collection)