Here you can find the source of toLongList(String[] array)
Parameter | Description |
---|---|
array | Input array |
public static List<Long> toLongList(String[] array)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Pablo Pavon-Marino. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html * * Contributors:/* w ww . j a v a 2 s . com*/ * Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1 * Pablo Pavon-Marino - from version 0.4.0 onwards ******************************************************************************/ import java.util.ArrayList; import java.util.List; public class Main { /** * Converts a {@code String} array to a {@code long} array. * * @param array Input array * @return New {@code long} array * */ public static List<Long> toLongList(String[] array) { List<Long> out = new ArrayList<Long>(array.length); for (int i = 0; i < array.length; i++) { if (array[i] == null) throw new RuntimeException("Null value in position " + i); out.add(Long.parseLong(array[i])); } return out; } /** * Converts a {@code String} array to a {@code long} array. * * @param array Input array * @param valueForNull Value for {@code null} positions * @return New {@code long} array * */ public static List<Long> toLongList(String[] array, long valueForNull) { List<Long> out = new ArrayList<Long>(array.length); for (String array1 : array) out.add(array1 == null ? valueForNull : Long.parseLong(array1)); return out; } }