在java中拆分字符串 [英] split string in java
本文介绍了在java中拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在分隔符上拆分字符串:和< space>以下是我想要的输出。
输入:1:123 456
我想做这样的输出:123, 456进入arraylist。
这是我的失败代码:
I need to split a string base on delimiter : and <space> Below are my desired output.
input: "1:123 456"
and i wanna make output like this: "123","456" into arraylist.
and here is my failed code:
List<String> skill = new ArrayList<String>();
List<String> result = new ArrayList<String>();
skill.add("1:123 456");
for (String st : skill) {
String[] array = st.split("[:]");
result.add(array[1]);
}
System.out.println(result);
请帮帮我...先谢谢。
please help me... thanks in advance.
推荐答案
for (String st : skill) {
String[] array = st.split(":");
result.Add(array[1].split("\\s+"));
}
这篇关于在java中拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文