Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

Arrays Class in Java

The Arrays class (package: java.util) provides a collection of static methods that are useful for working with arrays. Because the Arrays class provides only static methods, it has no constructors.

Method Description
static int binarySearch(array, key) Searches for the specified key value in an array. The return value is the index of the element that matches the key. The method returns -1 if the key can’t be found. The array and the key must be of the same type and can be any primitive type or an object.
static array copyOf(arrayOriginal, newLength) Returns an array that’s a copy of arrayOriginal. The newLength parameter need not equal the original array's length. If newLength is larger, the method pads the new array with zeros. If newLength is smaller, the method doesn't copy all of the original array’s values.
static array copyOfRange(arrayOriginal, from, to) Does what the copyOf method does, but copies only a selected slice of values (from one index to another) of the original array.
boolean deepEquals(array1, array2) Returns true if the two arrays have the same element values. This method works for arrays of two or more dimensions.
boolean equals(array1, array2) Returns true if the two arrays have the same element values. This method checks equality only for one-dimensional arrays.
static void fill(array, value) Fills the array with the specified value. The value and array must be of the same type and can be any primitive type or an object.
static void fill(array, from, to, value) Fills the elements indicated by the from and to int parameters with the specified value. The value and array must be of the same type and can be any primitive type or an object.
static void sort(array) Sorts the array in ascending sequence.
static void sort(array, from, to) Sorts the specified elements of the array in ascending sequence.
static String toString(array) Formats the array values in a string. Each element value is enclosed in brackets, and the element values are separated with commas.
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.