如何字符串转换为字符串数组在Java中? [英] How to convert String into String Array in Java?

查看:182
本文介绍了如何字符串转换为字符串数组在Java中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用逗号分隔这样的城市名称的字符串:{东京,纽约,阿姆斯特丹}

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

你如何将它转换为一个String []数组如{东京,纽约,阿姆斯特丹}

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

推荐答案

在分割,

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

如果 ST 有'{'和'}。你可能想要做沿...东西线

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

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

要摆脱'{'和'}'。

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

这篇关于如何字符串转换为字符串数组在Java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆