我目前正在尝试使用csv open在Java中显示一个名为"Haha2“的csv文件。不幸的是,当我打印arraylist时,我得到的是哈希码,而不是文件中包含的数字。
我已经尝试了.get()方法、.toArray()方法和.toString方法,但我仍然只能打印出散列代码。
下面是我的代码:
import au.com.bytecode.opencsv.*;
import java.io.*;
import java.util.*;
public class playlist{
public static void main (String args()) throws IOException {
CSVReader reader = new CSVReader(new FileReader("Haha2.asc"),';', '"',29);
List <String[]> data = new ArrayList <String[]>();
data = reader.readAll();
System.out.println(data);
}
}发布于 2011-08-10 16:35:16
下面是一个单行,它首先将列表转换为一个数组,提供一个数组组成的数组,然后调用Arrays.deepToString()。
System.out.println(Arrays.deepToString(data.toArray()));发布于 2011-08-10 16:29:32
要么遍历列表并对每个字符串数组调用Arrays.toString(),要么将List<String[]>转换为List<List<String>>。
发布于 2011-08-10 16:31:15
使用Arrays.toString()
for( String[] array : data ) {
System.out.println(Arrays.toString(data));
}https://stackoverflow.com/questions/7007826
复制相似问题