• 00032_ArrayList集合的遍历


    1、通过集合遍历,得到集合中每个元素,这是集合中最常见的操作

    2、集合的遍历与数组的遍历很像,都是通过索引的方式

     1 public class ArrayListDemo02 {
     2     public static void main(String[] args) {
     3         // 创建ArrayList集合
     4         ArrayList<Integer> list = new ArrayList<Integer>();
     5         // 添加元素到集合
     6         list.add(13);
     7         list.add(15);
     8         list.add(22);
     9         list.add(29);
    10         // 遍历集合
    11         for (int i = 0; i < list.size(); i++) {
    12             // 通过索引,获取到集合中每个元素
    13             int n = list.get(i);
    14             System.out.println(n);
    15         }
    16     }
    17 }

    3、get方法返回值的类型为集合中元素的类型

  • 相关阅读:
    预编译命令 #if DEBUG
    conda常用命令
    tensorflow 安装指南
    LocNET和池化理解
    同时安装cuda8和cuda9
    np.transpose
    python中List的slice用法
    书单
    训练工程
    linux 查看进程
  • 原文地址:https://www.cnblogs.com/gzdlh/p/8077891.html
Copyright © 2020-2023  润新知