Java Collection to Array asLongArray(final Collection ls)

Here you can find the source of asLongArray(final Collection ls)

Description

as Long Array

License

Open Source License

Declaration

public static long[] asLongArray(final Collection<? extends Number> ls) 

Method Source Code


//package com.java2s;
/*/*from w  ww  .  java 2 s.  co m*/
 * #%L
 * ImgLib2: a general-purpose, multidimensional image processing library.
 * %%
 * Copyright (C) 2009 - 2016 Tobias Pietzsch, Stephan Preibisch, Stephan Saalfeld,
 * John Bogovic, Albert Cardona, Barry DeZonia, Christian Dietz, Jan Funke,
 * Aivar Grislis, Jonathan Hale, Grant Harris, Stefan Helfrich, Mark Hiner,
 * Martin Horn, Steffen Jaensch, Lee Kamentsky, Larry Lindsey, Melissa Linkert,
 * Mark Longair, Brian Northan, Nick Perry, Curtis Rueden, Johannes Schindelin,
 * Jean-Yves Tinevez and Michael Zinsmaier.
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-2.0.html>.
 * #L%
 */

import java.util.Collection;

public class Main {
    public static long[] asLongArray(final Collection<? extends Number> ls) {
        final long[] d = new long[ls.size()];
        int i = 0;
        for (final Number num : ls)
            d[i++] = num.longValue();
        return d;
    }

    public static final int size(final long[] dim) {
        long size = 1;
        for (int i = 0; i < dim.length; ++i) {
            size *= dim[i];
        }
        return (int) size;
    }
}

Related

  1. asArray(Collection c)
  2. asArray(Collection collection, E[] a)
  3. asBooleanArray(Collection collection)
  4. asLongArray(java.util.Collection c)
  5. collectionToArray(Collection collection)
  6. collectionToIntArray(Collection c)
  7. collectionToIntArray(final Collection numbers)