对于字符串
String cow = "A cow jumped \n over the \n moon."
如何将字符串拆分为列表?
List<String> test = new ArrayList<String>();
Collections.addAll(test, cow).split("\n"));
上面的代码无效。
答案 0 :(得分:5)
试试这个:
String cow = "A cow jumped \n over the \n moon.";
List<String> test = Arrays.asList(cow.split("\n"));