1. 对象数组的概述和使用

  • 案例演示

    • 需求:我有5个学生,请把这个5个学生的信息存储到数组中,并遍历数组,获取得到每一个学生信息。

    • package com.heima.collection;
      
      import com.heima.bean.Student;
      
      public class Demo1_Array {
      
          /**
          需求:我有5个学生,请把这个5个学生的信息存储到数组中,并遍历数组,获取得到每一个学生信息。
           */
          public static void main(String[] args) {
              // 创建基本数据类型数组
              int[] arr_base = {1,2,3,4,5};
              
              // 创建引用数据类型数组
              Student[] arr = new Student[5];
              arr[0] = new Student("张三",23);  // 创建一个学生对象,存储在数组的第一个位置
              arr[1] = new Student("李四",24);
              arr[2] = new Student("王五",25);
      
              for(int i = 0; i < arr.length; i++) {
                  System.out.println(arr[i]);
              }
              
          }
      
      }
      View Code

相关文章:

  • 2021-07-21
  • 2022-03-09
  • 2022-02-10
  • 2021-09-07
猜你喜欢
  • 2021-04-23
  • 2021-06-26
  • 2021-09-05
  • 2021-06-21
  • 2021-05-14
  • 2021-06-29
  • 2021-04-01
相关资源
相似解决方案