-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
  • 268,359
  • 30
  • 341
  • 380
Lincoln White
  • 639
  • 2
  • 11
  • 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
  • 4,970
  • 2
  • 26
  • 42