【发布时间】:2021-12-07 09:33:51
【问题描述】:
我正在尝试迭代一个数组列表,然后在它找到一个字符时让它停止,在这种情况下是一个逗号。这就是我所拥有的:
这是数组列表:
List<String> collection = Arrays.asList(new String[]{"I", "f", " ", "y", "o", "u", " ", "g", "e", "t", " ", "a", " ", "t", "e", "x", "t", " ", "m", "e", "s", "s", "a", "g", "e", " ", "f", "r", "o", "m", " ", "a", "n", " ", "e", "m", "a", "i", "l", " ", "a", "d", "d", "r", "e", "s", "s", " ", "o", "r", " ", "n", "u", "m", "b", "e", "r", " ", "y", "o", "u", " ", "d", "o", "n", "'", "t", " ", "r", "e", "c", "o", "g", "n", "i", "z", "e", ",", " ", "i", "t", "'", "s", " ", "p", "r", "o", "b", "a", "b", "l", "y", " ", "b", "e", "s", "t", " ", "t", "o", " ", "i", "g", "n", "o", "r", "e", " ", "i", "t"});
这是我在 main 上使用的方法:showUntil();
private static void showUntil() {
for(String g : collection){
if(g.equals(",")){
System.out.println(g);
}
}
}
我在这个练习中使用 java。
【问题讨论】:
-
这能回答你的问题吗? How do you stop a loop from running in Java
标签: java arraylist collections iterator