public class Test {
public static void main(String args[])
{
String[] test={"this","this2"};
new Test().it(test);
}
public int it(String[] name)
{
return Integer.parseInt(name[0]);
}
}
我想将String数组更改为String.I得到异常,例如线程“main”中的异常java.lang.NumberFormatException:对于输入字符串:“this” // String change = name [0]; //返回Integer.parseInt(更改);
这个代码只能解决问题吗?
答案 0 :(得分:0)
您可以尝试以下代码将字符串数组转换为字符串
public class JavaApplication20 {
public static void main(String[] args) {
// TODO code application logic here
String test1 = "";
String[] test = {"this","this2"};
int length = test.length;
//System.out.println("Length :"+length);
for(int i=0; i<length; i++){
//System.out.println(test[i]);
test1 += test[i]+",";
}
int len = test1.length();
String str = test1.substring(0, len-1);
System.out.println("String :"+str);
}
}