Java.util.Arrays Class

Java.util.Arrays Class

Introduction

The java.util.Arrays class contains a static factory that allows arrays to be viewed as lists.Following are the important points about Arrays:

  • This class contains various methods for manipulating arrays (such as sorting and searching).
  • The methods in this class throw a NullPointerException if the specified array reference is null.

Class declaration

Following is the declaration for java.util.Arrays class:

public class Arrays
   extends Object

Class methods

S.N.Method & Description
1static <T> List<T> asList(T… a)

This method returns a fixed-size list backed by the specified array.

2static int binarySearch(byte[] a, byte key)

This method searches the specified array of bytes for the specified value using the binary search algorithm.

3static int binarySearch(byte[] a, int fromIndex, int toIndex, byte key)

This method searches a range of the specified array of bytes for the specified value using the binary search algorithm.

4static int binarySearch(char[] a, char key)

This method searches the specified array of chars for the specified value using the binary search algorithm.

5static int binarySearch(char[] a, int fromIndex, int toIndex, char key)

This method searches a range of the specified array of chars for the specified value using the binary search algorithm.

6static int binarySearch(double[] a, double key)

This method searches the specified array of doubles for the specified value using the binary search algorithm.

7static int binarySearch(double[] a, int fromIndex, int toIndex, double key)

This method searches a range of the specified array of doubles for the specified value using the binary search algorithm.

8static int binarySearch(float[] a, float key)

This method searches the specified array of floats for the specified value using the binary search algorithm.

9static int binarySearch(float[] a, int fromIndex, int toIndex, float key)

This method searches a range of the specified array of floats for the specified value using the binary search algorithm.

10static int binarySearch(int[] a, int key)

This method searches the specified array of ints for the specified value using the binary search algorithm.

11static int binarySearch(int[] a, int fromIndex, int toIndex, int key)

This method searches a range of the specified array of ints for the specified value using the binary search algorithm.

12static int binarySearch(long[] a, int fromIndex, int toIndex, long key)

This method searches a range of the specified array of longs for the specified value using the binary search algorithm.

13static int binarySearch(long[] a, long key)

This method searches the specified array of longs for the specified value using the binary search algorithm.

14static int binarySearch(Object[] a, int fromIndex, int toIndex, Object key)

This method searches a range of the specified array for the specified object using the binary search algorithm.

15static int binarySearch(Object[] a, Object key)

This method searches the specified array for the specified object using the binary search algorithm.

16static int binarySearch(short[] a, int fromIndex, int toIndex, short key)

This method searches a range of the specified array of shorts for the specified value using the binary search algorithm.

17static int binarySearch(short[] a, short key)

This method searches the specified array of shorts for the specified value using the binary search algorithm.

18static <T> int binarySearch(T[] a, int fromIndex, int toIndex, T key, Comparator<? super T> c)

This method searches a range of the specified array for the specified object using the binary search algorithm.

19static <T> int binarySearch(T[] a, T key, Comparator<? super T> c)

This method searches the specified array for the specified object using the binary search algorithm.

20static boolean[] copyOf(boolean[] original, int newLength)

This method copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length.

21static byte[] copyOf(byte[] original, int newLength)

This method copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.

22static char[] copyOf(char[] original, int newLength)

This method copies the specified array, truncating or padding with null characters (if necessary) so the copy has the specified length.

23static double[] copyOf(double[] original, int newLength)

This method copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.

24static float[] copyOf(float[] original, int newLength)

This method copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.

25static int[] copyOf(int[] original, int newLength)

This method copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.

26static long[] copyOf(long[] original, int newLength)

This method copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.

27static short[] copyOf(short[] original, int newLength)

This method copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.

28static <T> T[] copyOf(T[] original, int newLength)

This method copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length.

29static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType)

This method copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length.

30static boolean[] copyOfRange(boolean[] original, int from, int to)

This method copies the specified range of the specified array into a new array.

31static byte[] copyOfRange(byte[] original, int from, int to)

This method copies the specified range of the specified array into a new array.

32static char[] copyOfRange(char[] original, int from, int to)

This method copies the specified range of the specified array into a new array.

33static double[] copyOfRange(double[] original, int from, int to)

This method copies the specified range of the specified array into a new array.

34static float[] copyOfRange(float[] original, int from, int to)

This method copies the specified range of the specified array into a new array.

35static int[] copyOfRange(int[] original, int from, int to)

This method copies the specified range of the specified array into a new array.

36static long[] copyOfRange(long[] original, int from, int to)

This method copies the specified range of the specified array into a new array.

37static short[] copyOfRange(short[] original, int from, int to)

This method copies the specified range of the specified array into a new array.

38static <T> T[] copyOfRange(T[] original, int from, int to)

This method copies the specified range of the specified array into a new array.

39static <T,U> T[] copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType)

This method copies the specified range of the specified array into a new array.

40static boolean deepEquals(Object[] a1, Object[] a2)

This method returns true if the two specified arrays are deeply equal to one another.

41static int deepHashCode(Object[] a)

This method returns a hash code based on the “deep contents” of the specified array.

42static String deepToString(Object[] a)

This method returns a string representation of the “deep contents” of the specified array.

43static boolean equals(boolean[] a, boolean[] a2)

This method returns true if the two specified arrays of booleans are equal to one another.

44static boolean equals(byte[] a, byte[] a2)

This method returns true if the two specified arrays of bytes are equal to one another.

45static boolean equals(char[] a, char[] a2)

This method returns true if the two specified arrays of chars are equal to one another.

46static boolean equals(double[] a, double[] a2)

This method returns true if the two specified arrays of doubles are equal to one another.

47static boolean equals(float[] a, float[] a2)

This method returns true if the two specified arrays of floats are equal to one another.

48static boolean equals(int[] a, int[] a2)

This method returns true if the two specified arrays of ints are equal to one another.

49static boolean equals(long[] a, long[] a2)

This method returns true if the two specified arrays of longs are equal to one another.

50static boolean equals(Object[] a, Object[] a2)

This method returns true if the two specified arrays of Objects are equal to one another.

51static boolean equals(short[] a, short[] a2)

This method returns true if the two specified arrays of shorts are equal to one another.

52static void fill(boolean[] a, boolean val)

This method assigns the specified boolean value to each element of the specified array of booleans.

53static void fill(boolean[] a, int fromIndex, int toIndex, boolean val)

This method assigns the specified boolean value to each element of the specified range of the specified array of booleans.

54static void fill(byte[] a, byte val)

This method assigns the specified byte value to each element of the specified array of bytes.

55static void fill(byte[] a, int fromIndex, int toIndex, byte val)

This method assigns the specified byte value to each element of the specified range of the specified array of bytes.

56static void fill(char[] a, char val)

This method assigns the specified char value to each element of the specified array of chars.

57static void fill(char[] a, int fromIndex, int toIndex, char val)

This method assigns the specified char value to each element of the specified range of the specified array of chars.

58static void fill(double[] a, double val)

This method assigns the specified double value to each element of the specified array of doubles.

59static void fill(double[] a, int fromIndex, int toIndex, double val)

This method assigns the specified double value to each element of the specified range of the specified array of doubles.

60static void fill(float[] a, float val)

This method assigns the specified float value to each element of the specified array of floats.

61static void fill(float[] a, int fromIndex, int toIndex, float val)

This method assigns the specified float value to each element of the specified range of the specified array of floats.

62static void fill(int[] a, int val)

This method assigns the specified int value to each element of the specified array of ints.

63static void fill(int[] a, int fromIndex, int toIndex, int val)

This method assigns the specified int value to each element of the specified range of the specified array of ints.

64static void fill(long[] a, int fromIndex, int toIndex, long val)

This method assigns the specified long value to each element of the specified range of the specified array of longs.

65static void fill(long[] a, long val)

This method assigns the specified long value to each element of the specified array of longs.

66static void fill(Object[] a, int fromIndex, int toIndex, Object val)

This method assigns the specified Object reference to each element of the specified range of the specified array of Objects.

67static void fill(Object[] a, Object val)

This method assigns the specified Object reference to each element of the specified array of Objects.

68static void fill(short[] a, int fromIndex, int toIndex, short val)

This method assigns the specified short value to each element of the specified range of the specified array of shorts.

69static void fill(short[] a, short val)

This method assigns the specified short value to each element of the specified array of shorts.

70static int hashCode(boolean[] a)

This method returns a hash code based on the contents of the specified array.

71static int hashCode(byte[] a)

This method returns a hash code based on the contents of the specified array.

72static int hashCode(char[] a)

This method returns a hash code based on the contents of the specified array.

73static int hashCode(double[] a)

This method returns a hash code based on the contents of the specified array.

74static int hashCode(float[] a)

This method returns a hash code based on the contents of the specified array.

75static int hashCode(int[] a)

This method returns a hash code based on the contents of the specified array.

76static int hashCode(long[] a)

This method returns a hash code based on the contents of the specified array.

77static int hashCode(Object[] a)

This method returns a hash code based on the contents of the specified array.

78static int hashCode(short[] a)

This method returns a hash code based on the contents of the specified array.

79static void sort(byte[] a)

This method sorts the specified array of bytes into ascending numerical order.

80static void sort(byte[] a, int fromIndex, int toIndex)

This method sorts the specified range of the specified array of bytes into ascending numerical order.

81static void sort(char[] a)

This method sorts the specified array of chars into ascending numerical order.

82static void sort(char[] a, int fromIndex, int toIndex)

This method sorts the specified range of the specified array of chars into ascending numerical order.

83static void sort(double[] a)

This method sorts the specified array of doubles into ascending numerical order.

84static void sort(double[] a, int fromIndex, int toIndex)

This method sorts the specified range of the specified array of doubles into ascending numerical order.

85static void sort(float[] a)

This method sorts the specified array of floats into ascending numerical order.

86static void sort(float[] a, int fromIndex, int toIndex)

This method sorts the specified range of the specified array of floats into ascending numerical order.

87static void sort(int[] a)

This method sorts the specified array of ints into ascending numerical order.

88static void sort(int[] a, int fromIndex, int toIndex)

This method sorts the specified range of the specified array of ints into ascending numerical order.

89static void sort(long[] a)

This method sorts the specified array of longs into ascending numerical order.

90static void sort(long[] a, int fromIndex, int toIndex)

This method sorts the specified range of the specified array of longs into ascending numerical order.

91static void sort(Object[] a)

This method sorts the specified array of objects into ascending order, according to the natural ordering of its elements.

92static void sort(Object[] a, int fromIndex, int toIndex)

This method sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements.

93static void sort(short[] a)

This method sorts the specified array of shorts into ascending numerical order.

94static void sort(short[] a, int fromIndex, int toIndex)

This method sorts the specified range of the specified array of shorts into ascending numerical order.

95static <T> void sort(T[] a, Comparator<? super T> c)

This method sorts the specified array of objects according to the order induced by the specified comparator.

96static <T> void sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)

This method sorts the specified range of the specified array of objects according to the order induced by the specified comparator.

97static String toString(boolean[] a)

This method returns a string representation of the contents of the specified array of boolean.

98static String toString(byte[] a)

This method returns a string representation of the contents of the specified array of bytes.

99static String toString(char[] a)

This method returns a string representation of the contents of the specified array of chars.

100static String toString(double[] a)

This method returns a string representation of the contents of the specified array of doubles.

101static String toString(float[] a)

This method returns a string representation of the contents of the specified array of floats.

102static String toString(int[] a)

This method returns a string representation of the contents of the specified array of ints.

103static String toString(long[] a)

This method returns a string representation of the contents of the specified array of longs.

104static String toString(Object[] a)

This method returns a string representation of the contents of the specified array of ints.

105static String toString(short[] a)

This method returns a string representation of the contents of the specified array of shorts.

Methods inherited

This class inherits methods from the following classes:

  • java.util.Object

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.