在String中将String数组转换为int数组 [英] Converting a String array into an int Array in java
本文介绍了在String中将String数组转换为int数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是java编程的新手。我的问题是我有一个字符串数组,但当我尝试将其转换为int数组时,我一直在
I am new to java programming. My question is this I have a string array but when I am trying to convert it to an int array I keep getting
java.lang.NumberFormatException
我的代码是
private void processLine(String[] strings) {
Integer[] intarray=new Integer[strings.length];
int i=0;
for(String str:strings){
intarray[i]=Integer.parseInt(str);//Exception in this line
i++;
}
}
任何帮助都会非常感谢!!!
Any help would be great thanks!!!
推荐答案
要摆脱额外的空格,你可以改变这样的代码:
To get rid of additional whitespace, you could change the code like this:
intarray[i]=Integer.parseInt(str.trim()); // No more Exception in this line
这篇关于在String中将String数组转换为int数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文