如何在java中打印/记录字符串数组? [英] How to print/log array of string in java?

查看:107
本文介绍了如何在java中打印/记录字符串数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

小背景:

我有 csv 文件,它有很多行,每一行都有字符串元素,这样一行的一个例子是

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]

现在在我的解析器中,我正在解析这个 csv 文件并将文件中的每一行作为String[] 数据.在我的日志页面中,我需要有 id 以及文件中存在的行.

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.

目前,如果我尝试打印,则会得到像 [Ljava.lang.String;@1152e94 这样的值,我的问题是如何获得像 [20 这样的数组元素的实际列表, 11, 服装, TShirts, Abercombie, Gap]?

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]?

尝试使用默认的 toString() 但它仍然给出相同的 LString 数据.

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

推荐答案

使用 Arrays.toString(array) 以获得更易读的内容.

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

这篇关于如何在java中打印/记录字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆