昨天,当我在回答问题时使用迭代器和删除时收到ConcurrentModificationException错误我添加了一个通知,
当你有ArrayLists时,使用迭代器不是一个好主意.
你不需要深刻理解那个问题来回答这个问题.
在那里,我得到两条评论,我错了.
我的论点:
迭代器的代码可读性差得多.
有可能引发难以调试的ConcurrentModificationException.
你能解释一下吗?
问题:我们是否需要在ArrayList上使用迭代器?
UPD
这是关于显式使用Iterator.
对不起,如果这是重复,但我甚至想不出一种方法来搜索这个.我不确定要问这个问题的术语,所以我只会解决我的问题.
从我的测试来看,似乎if语句在尝试转到数组之前会退出[10].我总是这样吗?意思是,如果我在if语句中有一个&&而左侧是false,它会在测试第二个之前总是退出吗?就此而言,它会不会先测试左派?
public static void main(String[] args) {
boolean [] array = new boolean [10];
Arrays.fill(array, true);
int i = 10;
if(i < array.length && array[i]){
System.out.println("WhoHoo!");
}
}
Run Code Online (Sandbox Code Playgroud) 我已经看过有关此问题的其他几篇文章,但无法找到有关如何以编程方式确定代码点是否使用多个 2 字节(在 Windows 上)wchar_t 的任何详细信息。
一个例子:
const wchar_t* s2 = L"\U0002008A"; // The "Han" character
std::wstring in(s2); // length() == 2
Run Code Online (Sandbox Code Playgroud)
我想知道如何确定字符何时 length() > 1。
您如何解释空正则表达式和空捕获组正则表达式返回字符串长度加一个结果?
码
public static void main(String... args) {
{
System.out.format("Pattern - empty string\n");
String input = "abc";
Pattern pattern = Pattern.compile("");
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
String s = matcher.group();
System.out.format("[%s]: %d / %d\n", s, matcher.start(),
matcher.end());
}
}
{
System.out.format("Pattern - empty capturing group\n");
String input = "abc";
Pattern pattern = Pattern.compile("()");
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
String s = matcher.group();
System.out.format("[%s]: %d / %d\n", s, matcher.start(),
matcher.end());
}
}
}
Run Code Online (Sandbox Code Playgroud)
产量
Pattern - empty …
Run Code Online (Sandbox Code Playgroud)