zoukankan      html  css  js  c++  java
  • Java学习(四)

    数组

    • 数组是存储在一个连续的内存块中的元素集合。可以减少内存中变量搜索的时间
    • 数组中的每个元素必须是相同的数据类型,并且通过索引进行区分。数组中的第一个元素的索引为0
    • 单一值类型变量有时候很难满足应用程序的设计要求。数组类型变量可以同时存储多个同类型基础数据类型变量或对象

    声明数组

    • 声明一个数组

      int[] age;
      int ages[];  //这种方式不推荐
      age = new int[28];  
      命名了28个int空间,并且每个空间初始化为0;new
      

      new强制初始化数组,数组里面全初始化为0

    定义数组的方式

    double[] grade = new double[28];
    grade2[0] = 90;  //[index]index是索引
    String[] str = new String[10];
    

    Sting如果没有初始化,默认是null

    数组的复制

        String[] studentcopy = new String[5];
        for(int k =0;k<student.length;k++){
            studentcopy[k] = student[k];}
    

    arraycopy 进行数组的复制

        System.arraycopy(student, 0, studentcopy, 1, student.length-1);  
        System.out.print(studentcopy[2]);
        for(int l=0;l<5;l++){
            System.out.println(studentcopy[l]);}
    
    • 方法

      System.arraycopy(arg0, arg1, arg2, arg3, length);
      

    第一个arg0表示旧的数组,arg1copy的起始位置,arg2新的数组,arg3copy到新数组的位置,arg4数组的长度

  • 相关阅读:
    C# 访问USB(HID)设备
    IPad C盘中backup文件夹占用太多空间
    fastboot
    adb get android's ip
    Reading MMS
    Bitcoin
    内存问题导致编译不过!
    串口LOG 单编kernel
    Source Insight 格式化
    framework层的空指针会让系统重启
  • 原文地址:https://www.cnblogs.com/yeruheqi/p/5335475.html
Copyright © 2011-2022 走看看