按行分隔符将字符串拆分为列表?

Split string into list by line separator?

对于字符串

String cow = "A cow jumped \n over the \n moon."

如何将字符串拆分成列表?

List<String> test = new ArrayList<String>();
Collections.addAll(test, cow).split("\n")); 

上面的代码无效。

试试这个:

String cow = "A cow jumped \n over the \n moon.";
List<String> test = Arrays.asList(cow.split("\n"));