[英]Trouble getting and printing a returned value from one class to another in Java
I'm trying to import data from a CSV file.我正在尝试从 CSV 文件导入数据。 I don't have any issue about the importing process.我对导入过程没有任何问题。 But, when I'm passing an imported array from the CSV file to another method in another class, I can not get and print the values from the array.但是,当我将导入的数组从 CSV 文件传递到另一个 class 中的另一个方法时,我无法从数组中获取和打印值。 I got the following printing: [1, 2.0, [[Ljava.lang.String;@1e81f4dc].我得到以下打印:[1, 2.0, [[Ljava.lang.String;@1e81f4dc]。 "1" and "2" are imported values and are ok “1”和“2”是输入值,没问题
The real trouble for me is to get and print the values in "[Ljava.lang.String;@1e81f4dc]".对我来说真正的麻烦是获取并打印“[Ljava.lang.String;@1e81f4dc]”中的值。
I'd appreciate if you can help to know how to get the values in [Ljava.lang.String;@1e81f4dc] and print them.如果您能帮助了解如何获取 [Ljava.lang.String;@1e81f4dc] 中的值并打印它们,我将不胜感激。 The array in [Ljava.lang.String;@1e81f4dc] is a 2d array with double values. [Ljava.lang.String;@1e81f4dc] 中的数组是具有双精度值的二维数组。
The code I'm working on is the next one:我正在处理的代码是下一个:
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.*;
class importCsvToJava{
public static List<Object> getExample( ){
List<String[]> rowList = new ArrayList<String[]>();
try (BufferedReader br = new BufferedReader(new FileReader("/Users/user1/Desktop/csv1.csv"))) {
String line;
while ((line = br.readLine()) != null) {
String[] lineItems = line.split(";");
rowList.add(lineItems);
}
br.close();
}
catch(Exception e){
}
String[][] matrix = new String[rowList.size()][];
for (int i = 0; i < rowList.size(); i++) {
String[] row = rowList.get(i);
matrix[i] = row;
}
int a=1;
int b=2;
return Arrays.asList(a,b,matrix);
}
}
public class Callback {
public static void main(String[] args ) {
try{importCsvToJava.getExample();
List<Object> data = importCsvToJava.getExample();
System.out.println("Returned_matrix:"+data);
} catch (Exception e) {
System.out.println("Error during optimization");
e.printStackTrace();
}
}
}
String[][] mat = (String[][]) data.get(2);
for(String[] strings:mat)
{
for(String st:strings){
System.out.println(st);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.