gpt4 book ai didi

java - Java 中的 Array.toString 数据处理

转载 作者:行者123 更新时间:2023-11-30 07:17:20 24 4
gpt4 key购买 nike

在这种情况下,我对这里处理数据的方式感到困惑,我想会征求别人的意见。

arrayDataOne = [ HEllO, NAME, ADDRESS, ZIPCODE ] 

i.e
[0] = "HELLO"
[1] = "NAME"
[2] = "ADDRESS"
[3] = "ZIPCODE"

String arrayInString = ( Arrays.toString(arrayDataOne));

i.e
[ HEllO, NAME, ADDRESS, ZIPCODE ]

String[] arraySplit = arrayInString.split("\\|");

i.e
[0] = [[HEllO, NAME, ADDRESS, ZIPCODE ] ]

问题,
为什么字符串值显示为数组,尽管逻辑上它没有作为数组存储在 arrayInString 中?

为什么 arraySplit 在 [[ ****data**** ]] 中保存数据?看起来像数组的数组?

已编辑:(添加了更多答案详细信息)

要处理没有 "[""]"的字符串:阅读 link

最佳答案

  1. 因为 .toString 就是这样做的。阅读文档 http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html

    Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(double). Returns "null" if a is null.

  2. 因为当您尝试拆分它时它不匹配任何内容。因此,结果是字符串本身的单个桶

关于java - Java 中的 Array.toString 数据处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16269342/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com