[英]Java for( x : y) execution
I have the following for loop: 我有以下for循环:
for(String s : someString.split("\\s+")){
//do something
}
Does java execute the split() method each time the loop iterates, or does it do it only once and keep a temp array to iterate on? 每次循环迭代时java都执行split()方法,还是只执行一次并保持临时数组迭代?
它在使用之前将数组存储在临时变量中。
在字符串上不执行拆分一次,然后循环遍历结果
The split method is only called once. split方法只调用一次。 Think of the structure (also known as a for-each) as follows:
考虑结构(也称为for-each)如下:
More information can be had here: http://www.leepoint.net/notes-java/flow/loops/foreach.html 可以在这里获得更多信息: http : //www.leepoint.net/notes-java/flow/loops/foreach.html
PS: This works with Java 5 minimum. PS:这适用于Java 5最低要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.