-4

I have a string with city names separated with commas like this: {Tokyo, New York, Amsterdam}

How do you convert this to a String[] array like {"Tokyo", "New York", "Amsterdam"}

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Lincoln White
  • 639
  • 2
  • 12
  • 29
  • 1
    @Meiko That one shows how to split one word into individual letters. This question asks how to split the string by the commas. – Lincoln White Mar 22 '16 at 21:08

1 Answers1

7

Split on ",".

String st = "Tokyo, New York, Amsterdam"
String[] arr = st.split(",");

If st has '{' and '}'. You might want to do something along the lines of...

st = st.replace("{","").replace("}","");

to get rid of the '{' and '}'.

Debosmit Ray
  • 5,228
  • 2
  • 27
  • 43