Here you can find the source of arrayStringToArrayInt(final String[] as)
Parameter | Description |
---|---|
as | Array of strings to convert |
public static int[] arrayStringToArrayInt(final String[] as)
//package com.java2s; /*/*from ww w . j av a2s. c om*/ * Nividic development code * * This code may be freely distributed and modified under the * terms of the GNU Lesser General Public Licence. This should * be distributed with the code. If you do not have a copy, * see: * * http://www.gnu.org/copyleft/lesser.html * * Copyright for this code is held jointly by the microarray platform * of the ?cole Normale Sup?rieure and the individual authors. * These should be listed in @author doc comments. * * For more information on the Nividic project and its aims, * or to join the Nividic mailing list, visit the home page * at: * * http://www.transcriptome.ens.fr/nividic * */ public class Main { /** * Convert an array of strings to an array of integers. * @param as Array of strings to convert * @return An array of integers */ public static int[] arrayStringToArrayInt(final String[] as) { if (as == null) return null; int[] result = new int[as.length]; int j = 0; for (int i = 0; i < as.length; i++) { String s = as[i]; if (s == null) continue; try { result[j++] = Integer.parseInt(s.trim()); } catch (NumberFormatException e) { continue; } } int[] finalResult = new int[j]; System.arraycopy(result, 0, finalResult, 0, j); return finalResult; } }