编程知识 cdmana.com

Four ways of traversing list in Java

1 package com.tiandy.core.rest; 2  3 import java.util.ArrayList; 4 import java.util.Iterator; 5 import java.util.List; 6  7 /** 8  * List  Iterated set  9  * @data 2020.12.1210  *11 */12 public class TestList {13 14  public static void main(String[] args) {15   //  Loop traversal List Of 4 Medium method 16   List<String> strList = new ArrayList<>();17   strList.add("aaa");18   strList.add("bbb");19   strList.add("ccc");20   //  The first one is :  Ordinary for Loop traversal mode  ( The advantage is that you can choose the subscript )21   for (int i = 0; i < strList.size(); i++) {22    System.out.println(strList.get(i));23   }24   //  The second kind :  Enhanced for loop 25   for (String str : strList) {26    System.out.println(str);27   }28   //  The third kind of :  Use Iterator iterator 29  .........

版权声明
本文为[Irving the procedural ape]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225130401772U.html

Scroll to Top