java数组的定义与使用,数组与方法的传递,数组的操作方法,新型foreach循环(重点),stream的数组循环(重点),对象数组(重点)

数组的定义方法:

*声明并开辟数组:数组类型 数组名称[] = new 数据类型[长度];

*分布完成:

声明数组:数据类型  数组名称 [] = null;

开辟数组:数组名称 = new 数组类型[长度]

常用申明方式:

int data [] = new int [] {1,2,3}

数组方法传递

package day1;

public class Arrayobj {
    public static void main(String[] args){
        //在主函数里面声明数组
        int data [] = new int[3];
        int arr [] = new int[]{1,2,3};
        change(arr);
        for(int i:arr){
            System.out.println(i);
        }
    }
    public static void change(int temp[]){
        for (int i = 0;i<temp.length;i++){
            temp[i] *=2;
        }
    }
}

数组的拷贝:

System.arraycopy(原数组名称,原数组拷贝开始的索引,目标数组名称,目标数组拷贝开始索引,长度)

扫描二维码关注公众号,回复: 4799428 查看本文章

数组排序:

java.util.Arrays.sort(arr)

新型for循环

 int dataB[] = new int[]{6, 7, 9, 8};
for(int item:dataB){
            System.out.println(item);
        }

stream的数组循环

    Arrays.stream(dataB).forEach(System.out::println);

对象数组一个引用类型里面引用了其他引用类型,对象数组的每一项都要申明

猜你喜欢

转载自blog.csdn.net/memedadexixaofeifei/article/details/85036884