java - 迭代一个链表 [英] java - iterating a linked list

查看:18
本文介绍了java - 迭代一个链表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在 java 中的链表上使用 for-each 循环,是否保证我会按顺序迭代元素它们出现在列表中的哪个位置?

if I use a for-each loop on a linked list in java, is it guaranteed that I will iterate on the elements in the order in which they appear in the list?

推荐答案

链表保证按顺序执行.

来自文档

有序集合(也称为顺序).此界面的用户可以精确控制在什么地方列出每个插入的元素.这用户可以通过他们的访问元素整数索引(列表中的位置),并搜索列表中的元素.

An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.

iterator()以适当的顺序返回此列表中元素的迭代器.

iterator() Returns an iterator over the elements in this list in proper sequence.

这篇关于java - 迭代一个链表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆