2

I'm confused the way data has been manipulated here in this case, thought will seek someones advice.

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

Question,
Why does string value displays as array though logically it's not stored as array in arrayInString ?

Why does arraySplit holds data with in [[ ****data**** ]] ? seems like array of array?

Edited: ( added more answer details )

To handle string without "[" "]" : read link

Community
  • 1
  • 1
Mad-D
  • 4,479
  • 18
  • 52
  • 93

1 Answers1

4
  1. Because that's what .toString does. Read the doc 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. Because it does not match anything when you try to split it. The result therefore is a single bucket the string itself

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
marcadian
  • 2,608
  • 13
  • 20
  • so if i'm interested in just plain string of HEllO, NAME, ADDRESS, ZIPCODE without [ ], i should do regex replace on it ? or is it a bad practice ? – Mad-D Apr 29 '13 at 00:24
  • 1
    If you want it as array, then do not use .toString. What actually are you trying to do? – marcadian Apr 29 '13 at 03:14
  • thanks i did find the answer, used StringBuilder to create string. – Mad-D Apr 29 '13 at 03:16