[英]How to write “for x in list” in Java?
I was wondering how to express a certain type of for loop in Java. 我想知道如何在Java中表达某种类型的for循环。
In Python I would use: 在Python中我会使用:
for x in lst1:
return 10
How would I do this in Java? 我怎么用Java做这个?
I know for the range for-loops, I use
for(int i=0; i<100; j++) {
return "asdf"
}
I just want to know how to do the other type of loop 我只是想知道如何做其他类型的循环
int[] myints = {1, 2, 3, 4, 5};
for(int i : myints) {
System.out.println(i);
}
int[] lst1 = {1,2,4,5,6,7,8,9};
for (int x : lst1){
return 10;
}
That's--as far as I'm aware--the exact conversion of your python code. 那 - 据我所知 - 你的python代码的确切转换。 I recently did a video tutorial on iterating through a list that you and other's will most likely benefit from watching. 我最近做了一个关于迭代列表的视频教程 ,你和其他人最有可能从观看中获益。
Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.