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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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 ?
If you want it as array, then do not use .toString. What actually are you trying to do?
thanks i did find the answer, used StringBuilder to create string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.