出于以下情况,这是重用section矢量的首选方式?
Iterator<Vector> outputIter = parsedOutput.iterator();
while(outputIter.hasNext()) {
Vector section = outputIter.next();
}
Run Code Online (Sandbox Code Playgroud)
要么
Vector section = null;
while(outputIter.hasNext()) {
section = outputIter.next();
}
Run Code Online (Sandbox Code Playgroud)
我更喜欢第二个版本,因为在循环结束后你的范围内没有未使用的变量.
但是,怎么样
for (Vector section: parsedOutput) {
...
}
Run Code Online (Sandbox Code Playgroud)
?