Home>

I want to store the stored value of String [] correctly in List.

I confirmed by debugging that "" 1 "," 2 "," 3 "," 4 "" is stored in String [] data. However, when stored in Listlist, "[Ljava.lang.String;@ 69d289f4, [Ljava.lang.String;@ 9b644b1, [Ljava.lang.String;@ 78c42408, [Ljava.lang.String" A value such as "@ c24a54a," is stored.

Corresponding source code
package com.example.demo;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Test {
    public static List<String []>getCsv () {
        String path = "./csv/test.csv";
        List<String []>list = new ArrayList<String []>();
        FileInputStream fi = null;
        InputStreamReader is = null;
        BufferedReader br = null;
        try {
            fi = new FileInputStream (path);
            is = new InputStreamReader (fi);
            br = new BufferedReader (is);
            String line;
            while ((line = br.readLine ())! = null) {
                String [] data = line.split (",");
                list.add (data);
            }
        } catch (Exception e) {
            e.printStackTrace ();
        } finally {
            try {
                br.close ();
            } catch (Exception e) {
                e.printStackTrace ();
            }
        }
        return list;
    }
}
What I tried

I have confirmed by debugging that "" 1 "," 2 "," 3 "," 4 "" are stored in String [] data.

Supplementary information (FW/tool version, etc.)

Language: Java
FW: Thymeleaf

  • Answer # 1

    It is a specification when outputting the array as it is. The value itself is included.
    For more information, talk about toString () starting by passing an array to System.out.println