Here you can find the source of toLongArray(String array)
String should have the format "[1,2,3]"
.
Parameter | Description |
---|---|
array | the string to be cast |
public static long[] toLongArray(String array)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w. j a v a 2s . com * Cast a string to an array of longs * <p> * String should have the format <code>"[1,2,3]"</code>. * * @param array * the string to be cast * @return an array containing the parsed longs */ public static long[] toLongArray(String array) { // Empty array [] if (array.length() == 2) return new long[0]; String[] cast = array.substring(1, array.length() - 1).split(","); long[] result = new long[cast.length]; for (int i = 0; i < cast.length; i++) { result[i] = Long.valueOf(cast[i]); } return result; } }