-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"}

1
  • 1
    @Meiko That one shows how to split one word into individual letters. This question asks how to split the string by the commas. Commented Mar 22, 2016 at 21:08

1 Answer 1

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 '}'.

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

1 Comment

@DougStevenson Haha Let me update it :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.