数组

//一维数组    
    int myarry[] = new int [5];    

    //索引是从0开始
    myarry[0] = 100;
    myarry[2] = 200;
    
    //初始化
    int arry[] = new int[]{1,2,3,4,5};
    //
    int sz[] = {1,2,3,4,5,6,7};
    
    //遍历数组
    for(int i = 0; i < myarry.length; i++)
    {
        System.out.println("myarry =" + myarry[i]);
    }
    
    
    //二维数组
     int shuzu2 [][]= {{1,6,3},{8,2,4}};
    
     for(int a[] : shuzu2 )
    {
        for(int b : a)
        {
            System.out.print(b + " ");
        }
        System.out.println();
    }
    
    //操作数组
    Arrays.sort(shuzu2);//排序
    
    //复制数组
    int[][] shuzu3  = shuzu2;
    int []shuzu4 = Arrays.copyOf(sz, 3);//复制制定长度.从头开始。
    int []shuzu5 = Arrays.copyOfRange(sz, 1, 4);//复制索引值1到3之间的数组
    
    //查询数组,返回索引值,如果没有找到返回负数,可以判断是否包含某元素。
    Arrays.binarySearch(sz, 3);
    
    //填充数组
    Arrays.fill(sz, 2);//一次性全部填充替换
    Arrays.fill(myarry, 1, 3, 8);//选择性填充替换,第一个索引值包括,第二个索引值不包括,第三个为填充替换值。
原文地址:https://www.cnblogs.com/OldZhao/p/4863982.html