0

I am currently trying to display a csv file called "Haha2" using csv open in Java. Unfortunately when I print the arraylist I get the hashcode and not the numbers that are contained in the file.

I have tried the .get() method and the .toArray() and .toString methods but I am still only able to print out the hashcode.

Here's my code:

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);
   }
}
3
  • 1
    You have to loop through all elements in data and then for each element you again have to loop for all elements in each String[]. Commented Aug 10, 2011 at 8:26
  • @Harry: You should make that an answer! Commented Aug 10, 2011 at 8:29
  • @Oli: there are already similar answers. Commented Aug 10, 2011 at 8:38

5 Answers 5

4

Here is a one-liner which first converts the list to an array giving you an array-of-arrays and then calling Arrays.deepToString().

System.out.println(Arrays.deepToString(data.toArray()));
Sign up to request clarification or add additional context in comments.

Comments

2

Either loop through your list and call Arrays.toString() on each of the array of Strings, or transform List<String[]> into List<List<String>>.

Comments

1

Use Arrays.toString():

for( String[] array : data ) {
    System.out.println(Arrays.toString(data));
}

Comments

0

iterate over the List and than over the array:

for( String[] array : data ) {
    for( String string : array ) {
        System.out.println(string);
    }
    System.out.println("---");
}

Comments

0
for (String[] arr : data) {
    System.out.println(java.util.Arrays.asList(arr));
    System.out.println("...");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.