zoukankan      html  css  js  c++  java
  • 数组

    数组:相同数据类型的数据的组合。

    如: int score1 = 72;
    int score2 = 90;
    int score3 = 59;

    使用数组:
    1.数组的初始化
    int[] scores1 = new int[]{72,90,59};//静态初始化:在声明并初始化数组与给数组相应的元素赋值操作同时进行。
    int scores2[] = new int[3];//动态初始化:在声明并初始化数组与给数组相应的元素赋值操作分开进行。
    scores2[0] = 72;
    scores2[1] = 90;
    scores2[2] = 59;
    //声明数组的错误写法:
    1)String[] names = new String[5]{"AA","BB","CC"};
    2)int i[10];
    3)int i = new int[];
    注:不管是动态还是静态初始化数组,一定在创建的时候,就指明了数组的长度!
    2.如何引用数组元素:通过数组的下角标的方式。下角标从0开始,到n-1结束。其中n为数组的长度。
    3.数组的长度:通过数组的属性length来调用。
    System.out.println(scores2.length);//3
    4.如何遍历数组
    for(int i = 0;i < scores1.length;i++){
    System.out.println(scores1[i]);
    }
    5.关于数组元素的默认初始化值
    1)byte short int long 而言:0
    2)float double 而言:0.0
    3)char而言:空格
    4)boolean而言:false
    5)引用类型变量而言:null

    6.数组的内存结构

  • 相关阅读:
    待重写
    待重写
    待重写
    ReflectionUtils使用
    kafka消费组、消费者
    待重写
    Map接口常用实现类学习
    利用httpClient发起https请求
    sql常用格式化函数及字符串函数
    method reference
  • 原文地址:https://www.cnblogs.com/Codinginging/p/10734477.html
Copyright © 2011-2022 走看看