[英]JAVA Convert 2d array of strings to 2d array of Number type
i have got little problem.我有一点问题。 I scanned numbers from .csv file into 2d array of strings.
我将 .csv 文件中的数字扫描到二维字符串数组中。 Now i need to parse it into 2d array of Number type.
现在我需要将其解析为 Number 类型的二维数组。 Not int or double.
不是 int 或 double。 The error says:
错误说:
Required type: com.sun.org.apache.xpath.internal.operations.Number Provided: java.lang.Number所需类型:com.sun.org.apache.xpath.internal.operations.Number 提供:java.lang.Number
Can you please take a look ?你能看一下吗?
for (int a = 0; a < rows; a++) {
for (int b = 0; b < cols; b++) {
parsedContent[a][b] = NumberFormat.getInstance().parse(arrayOfStrings[a][b]);
}
}
I have a small sample programm for you:我有一个小示例程序供您使用:
public static void main(String[] args) throws Exception{
int rows = 2;
int cols = 3;
String[][] arrayOfStrings = {{"1.1","2.222222222","3.333"},{"4.44","5555","666"}};
Number[][] parsedContent = new Number[rows][cols];
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
for (int a = 0; a < rows; a++) {
for (int b = 0; b < cols; b++) {
parsedContent[a][b] = numberFormat.parse(arrayOfStrings[a][b]);
System.out.println(parsedContent[a][b]);
}
}
}
Outout:输出:
1.1
2.222222222
3.333
4.44
5555
666
Is that what you mean?你是这个意思吗? Otherwise I need more code details and some sample Strings.
否则我需要更多代码细节和一些示例字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.