我对这种情况下数据的处理方式感到困惑,我想寻求某人的建议。
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
最佳答案
因为这就是 .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.
因为当您尝试拆分它时它与任何内容都不匹配。因此,结果是字符串本身的单个存储桶
关于java - Java 中的 Array.toString 数据处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16269342/