本文介绍了如何将String转换为ArrayList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的字符串中,我可以使用逗号分隔的任意数量的单词。我希望每个单词都添加到ArrayList中。例如:
In my String, I can have an arbitrary number of words which are comma separated. I wanted each word added into an ArrayList. E.g.:
String s = "a,b,c,d,e,.........";推荐答案
尝试类似
List<String> myList = new ArrayList<String>(Arrays.asList(s.split(",")));
- Arrays.asList documentation
- String.split 文档
- ArrayList(Collection) 构造函数文档
- Arrays.asList documentation
- String.split documentation
- ArrayList(Collection) constructor documentation
演示:
String s = "lorem,ipsum,dolor,sit,amet"; List<String> myList = new ArrayList<String>(Arrays.asList(s.split(","))); System.out.println(myList); // prints [lorem, ipsum, dolor, sit, amet]
此帖已被重写为此处。
更多推荐
如何将String转换为ArrayList?
发布评论