Chapter 21 (Web hosting e commerce) Collections 1205 58 // compare array
Chapter 21 Collections 1205 58 // compare array contents 59 public void printEquality() 60 { 61 boolean b = Arrays.equals( intValues, intValuesCopy ); 62 63 System.out.println( “intValues ” + ( b ? “==” : “!=” ) 64 + ” intValuesCopy” ); 65 66 b = Arrays.equals( intValues, filledInt ); 67 68 System.out.println( “intValues ” + ( b ? “==” : “!=” ) 69 + ” filledInt” ); 70 } 71 72 // execute application 73 public static void main( String args[] ) 74 { 75 UsingArrays usingArrays = new UsingArrays(); 76 77 usingArrays.printArrays(); 78 usingArrays.printEquality(); 79 80 int location = usingArrays.searchForInt( 5 ); 81 System.out.println( ( location >= 0 ? 82 “Found 5 at element ” + location : “5 not found” ) + 83 ” in intValues” ); 84 85 location = usingArrays.searchForInt( 8763 ); 86 System.out.println( ( location >= 0 ? 87 “Found 8763 at element ” + location : 88 “8763 not found” ) + ” in intValues” ); 89 } 90 91 } // end class UsingArrays doubleValues: 0.2 3.4 7.9 8.4 9.3 intValues: 1 2 3 4 5 6 filledInt: 7 7 7 7 7 7 7 7 7 7 intValuesCopy: 1 2 3 4 5 6 intValues == intValuesCopy intValues != filledInt Found 5 at element 4 in intValues 8763 not found in intValues Fig. 21.1Using methods of class Arrays(part 3 of 3). Fig. 21.1 Line 18 calls Arrays static method fill to populate all 10 elements of array filledInt with 7s. Overloaded versions of fill allow the programmer to populate a specific range of elements with the same value. Line 20 sorts the elements of array doubleValues. Overloaded versions of sort allow the programmer to sort a specific range of elements. Arrays static method sortorders the array s elements in ascending order by default. We discuss how to sort in descending order later in the chapter. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/12/01
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web and email hosting services