你可以使用递归.
public void doSomethingToAll(List list)
{
// Begin the recursion.
doSomethingToAll(list, 0);
}
private void doSomethingToAll(List list, int index)
{
// Break the recursion when we have processed the entire list.
if (index >= list.size()) return;
// Do whatever you want with the list.
process(list.get(index));
// Recursive step. Process the next element.
doSomethingToAll(list, index + 1);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3688 次 |
| 最近记录: |