用JAVA 将数字字符串“12,35,11”转化为Long型数组

2024年11月18日 22:26
有4个网友回答
网友(1):

public class Test{
public static void main(String[] args) {
String s = "12,35,11";
String[] s1 = s.split(",");
Long[] l = new Long[s1.length];

for( int i = 0; i < l.length; i++){
l[i] = new Long(s1[i]);
}

//输出转换结果
for( int i = 0; i < l.length; i++){
System.out.println(l[i]);
}
}
}

网友(2):

String[] arr=(12,35,11).split(",")
然后转化一下就行了!

网友(3):

String [] array = ("12,35,11").split(",");

long [] long_array = array.length;

for(int i=0;i{
long_array[i] = Long.parseLong(array[i]);
}

网友(4):

package cn.hit.edu.lxc;

public class awsd {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] s = ("12,35,11").split(",");
Long[] l = new Long[s.length];

for( int i = 0; i < l.length; i++){
l[i] = new Long(s[i]);
System.out.println(l[i]);
}
}
}