2

I've got these code lines to read from a CSV file:

public static void main(String[] args) throws FileNotFoundException, IOException {

    CSVReader reader = new CSVReader(new FileReader("file.csv"));
    List myEntries = reader.readAll();
    System.out.println(myEntries);
}

But what it returns to me is:

[[Ljava.lang.String;@6bc7c054, [Ljava.lang.String;@232204a1, etc.

My CSV file contains columns and rows (just like an Excel file). I have name, society, import, ...

How do I read exactly what's inside the file?

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
Marco
  • 322
  • 1
  • 3
  • 15

2 Answers2

2

Firstly, don't use raw types: List<String[]> myEntries.

Secondly, what you are seeing there is the somewhat useless result of converting each list element - a String[] - to a String. You almost never want to call toString() on an array, whether implicitly or explicitly.

Instead, iterate through the list, using Arrays.toString() to print each element "usefully":

for (String[] row : myEntries) {
  System.out.println(Arrays.toString(row));
}
Andy Turner
  • 137,514
  • 11
  • 162
  • 243
0

The Java 8 version:

myEntries.forEach( stringArray -> System.out.println( Arrays.toString( stringArray ) ) );

Or if newlines aren't necessary:

System.out.println( Arrays.deepToString( myEntries.toArray() ) );
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107