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 
posted @ 2007-06-29 10:57  樊凯  阅读(501)  评论(0编辑  收藏  举报