Arrays in Java 5

Source: Internet
Author: User
1 package com. kay. java5.test1;
2
3 import java. util. Arrays;
4 /************************************** ************
5 * @ Title array in 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 // compare two Arrays
30 if (Arrays. equals (array, otherarray )){
31 System. out. println ("the two arrays are the same! ");
32} else {
33 System. out. println ("the two arrays are different! ");
34}
35
36 Arrays. fill (array, 2, 10, 3); // The Value assignment parameters are <array start index (inclusive) end index (excluded) values>
37 array [11] = 4;
38
39 // print the Array
40 System. out. println (Arrays. toString (array ));
41 // sort the Array
42 Arrays. sort (array );
43 // print the sorted Array
44 System. out. println (Arrays. toString (array ));
45
46 // locate the index address of a specific value
47 int index = Arrays. binarySearch (array, 4 );
48 System. out. println ("4 index address:" + index );
49
50 *******************/
51
52 String [] [] strarry = {
53 {"A", "A", "B "},
54 {"A", "AC", "D "},
55 {"B", "V", "X "},
56 };
57
58 // toString () method of multi-dimensional array
59 System. out. println ("multi-dimensional array printing:" + 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 // multi-dimensional array comparison
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.