zoukankan      html  css  js  c++  java
  • java5中的Arrays

     1 package com.kay.java5.test1;
     2 
     3 import java.util.Arrays;
     4 /**************************************************
     5  * @Title Java5中的数组
     6  * @author KAY
     7  * @Date 2007-06-29
     8  **************************************************/
     9 public class ArraysTest {
    10 
    11     public int[] test;
    12     
    13     public ArraysTest(int i){
    14         test = new int[i];
    15         for (int j = 0; j < test.length; j++) {
    16             test[j] = (1000 - (300 + j));
    17         }
    18     }
    19     
    20     public int[] getArray(){
    21         return test;
    22     }
    23     
    24     public static void main(String[] args) {
    25         ArraysTest at = new ArraysTest(50);
    26         int[] array = at.getArray();
    27         int[] otherarray = at.getArray().clone();
    28         
    29         //比较两个数组
    30         if(Arrays.equals(array, otherarray)){
    31             System.out.println("两个数组是相同的!");
    32         }else{
    33             System.out.println("两个数组是不同的!");
    34         }
    35         
    36         Arrays.fill(array, 210,3);//赋值 参数分别为< 数组 开始索引(包括) 结束索引(不包括) 值>
    37         array[11= 4;
    38         
    39         //打印数组 
    40         System.out.println(Arrays.toString(array));
    41         //对数组排序
    42         Arrays.sort(array);
    43         //打印排过序的数组
    44         System.out.println(Arrays.toString(array));
    45         
    46         //找出特定值的index地址
    47         int index = Arrays.binarySearch(array, 4);
    48         System.out.println("4的index地址为:" + index);
    49         
    50         /**************多维数组操作*******************/
    51         
    52         String[][] strarry = {
    53                 {"A","A","B"},
    54                 {"A","AC","D"},
    55                 {"B","V","X"},
    56         };
    57         
    58         //多维数组的toString()方法
    59         System.out.println("多维数组打印:" + Arrays.deepToString(strarry));
    60         
    61         String[][] strarry2 = {
    62                 {"A","A","B"},
    63                 {"A","AC","D"},
    64                 {"B","V","X"},
    65         };
    66         String[][] strarry3 = {
    67                 {"C","C","C"},
    68                 {"A","AC","D"},
    69                 {"B","V","X"},
    70         };
    71         
    72         //多维数组比较
    73         if(Arrays.deepEquals(strarry, strarry2)){
    74             System.out.println("strarry = strarry2");
    75         }else{
    76             System.out.println("strarry != strarry2");
    77         }
    78         
    79         if(Arrays.deepEquals(strarry, strarry3)){
    80             System.out.println("strarry = strarry3");
    81         }else{
    82             System.out.println("strarry != strarry3");
    83         }
    84     }
    85 }
    86 
  • 相关阅读:
    mac 10.15.7 修改PATH
    oc 属性类型一般用法
    ubuntu解压zip文件名乱码
    telnet 退出
    docker 根据容器创建镜像
    mac android adb device 没有显示设备
    Yii2 查看所有的别名 alias
    Yii2 App Advanced 添加 .gitignore
    ubuntu 18.04 搜狗突然就提示乱码
    An error occured while deploying the file. This probably means that the app contains ARM native code and your Genymotion device cannot run ARM instructions. You should either build your native code to
  • 原文地址:https://www.cnblogs.com/kay/p/799870.html
Copyright © 2011-2022 走看看