本帖最后由 被淹死的虫子 于 2015-5-28 16:35 编辑
List集合有那么多遍历元素的方法。。。该怎么用啊?
- <p>public class ListDemo {</p><p> public static void main(String[] args) {
- // TODO Auto-generated method stub
- List<String> list = new ArrayList<String>();
-
- list.add("abc1");
- list.add("abc2");
- list.add("abc3");
- list.add("abc4");
- //通用迭代器
- Iterator<String> it = list.iterator();
- while(it.hasNext()){
- System.out.println(it.next());
- }
- System.out.println();
- //ltst迭代器
- ListIterator<String> lit = list.listIterator();
- while(lit.hasNext()){
- System.out.println(lit.next());
- }
- System.out.println();
- //for循环遍历
- for (int i = 0; i < list.size(); i++) {
- System.out.println(list.get(i));
- }
- }</p><p>}
- </p><p> </p>
复制代码
|
|