将增强的for循环转换为常规for循环 [英] Converting an enhanced for loop to a regular for loop
本文介绍了将增强的for循环转换为常规for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
for (String title : titles)
{
// Code
}
如果我将其转换为如下所示的for循环:
If I were to convert that to a for loop that looked like this:
for (int i = 0; i < array.length(); i ++)
它会是什么样子?
推荐答案
这假定 titles
是一个列表< String>
,这是问题下面的评论所暗示的。
This assumes that titles
is a List<String>
, which is implied by the comments below the question.
for (int i = 0; i < titles.size(); i++) {
String title = titles.get(i);
//Do something with title
}
这篇关于将增强的for循环转换为常规for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文