How to print/log array of string in java?

35,278

Solution 1

Use Arrays.toString(array) to obtain something more human-readable.

Solution 2

use Arrays.toString(array); it will work

Share:
35,278
Rachel
Author by

Rachel

I am here for learning and I learn different aspects of Computer Science from the Valuable Answers which I get from Stackoverflow Users. Thank you SO Community. I owe my knowledge to you.

Updated on January 13, 2020

Comments

  • Rachel
    Rachel over 4 years

    Little Background:

    I have csv file which has lots of rows and each row has string elements, one example of such a row would be

    String[] data = [20,11,Clothing,TShirts,Abercombie,Gap]
    
    data.toString() = [Ljava.lang.String;@1152e94]
    

    Now in my parser, I am parsing this csv file and getting each row present in the file as String[] data. In my log page, I need to have the id as well as the row present in the file.

    Currently, if I try to print then am getting values like [Ljava.lang.String;@1152e94, my question is how can i get actual list of array elements like [20, 11, Clothing, TShirts, Abercombie, Gap]?

    Tried using default toString() but still it give same LString data.