OOPs (Object-Oriented Programming) ConceptsObject and ClassesClass AttributesClass MethodsMethodsVariable ScopesConstructorsAccess ModifiersInheritanceAggregationPolymorphismOverridingMethod OverloadingDynamic BindingStatic BindingInstance Initializer BlockAbstractionEncapsulationInterfacesPackagesInner classesStatic ClassesAnonymous ClassesSingleton ClassWrapper ClassesEnum Class
Feedback
Submit request if you have any questions.
Course
Java Arrays - Class
Java Tutorial
This Java tutorial is tailored for newcomers, offering a journey from basic principles to complex Java programming techniques. Completing this tutorial equips you with a solid understanding of Java, preparing you for advanced learning. You'll emerge ready to tackle the challenges of becoming a top-tier software engineer, with the skills to innovate and excel in the vast world of software development.
Arrays Class | Array Methods
Introduction
- 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.
Arrays Class Declaration
Following is the declaration for java.util.Arrays class
public class Arrays extends Object
Arrays Class Methods
Sr.No. | Method & Description |
---|---|
1 | This method returns a fixed-size list backed by the specified array. |
2 | This method searches the specified array of bytes for the specified value using the binary search algorithm. |
3 | This method searches the specified array of chars for the specified value using the binary search algorithm. |
4 | This method searches the specified array of doubles for the specified value using the binary search algorithm. |
5 | This method searches the specified array of floats for the specified value using the binary search algorithm. |
6 | This method searches the specified array of ints for the specified value using the binary search algorithm. |
7 | This method searches a range of the specified array of longs for the specified value using the binary search algorithm. |
8 | This method searches the specified array for the specified object using the binary search algorithm. |
9 | This method searches the specified array of shorts for the specified value using the binary search algorithm. |
10 | This method searches the specified array for the specified object using the binary search algorithm. |
11 | This method compares two boolean arrays lexicographically. |
12 | This method compares two byte arrays lexicographically. |
13 | This method compares two char arrays lexicographically. |
14 | This method compares two double arrays lexicographically. |
15 | This method compares two float arrays lexicographically. |
16 | This method compares two int arrays lexicographically. |
17 | This method compares two long arrays lexicographically. |
18 | This method compares two short arrays lexicographically. |
19 | This method compares two Object arrays lexicographically. |
20 | This method compares two byte arrays lexicographically, numerically treating elements as unsigned. |
21 | This method compares two int arrays lexicographically, numerically treating elements as unsigned. |
22 | This method compares two long arrays lexicographically, numerically treating elements as unsigned. |
23 | This method compares two short arrays lexicographically, numerically treating elements as unsigned. |
24 | This method copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length. |
25 | This method copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length. |
26 | This method copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length. |
27 | This method copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length. |
28 | This method copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. |
29 | This method copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. |
30 | This method copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. |
31 | This method copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. |
32 | This method copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length. |
33 | This method copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length. |
34 | This method copies the specified range of the specified array into a new array. |
35 | This method copies the specified range of the specified array into a new array. |
36 | This method copies the specified range of the specified array into a new array. |
37 | This method copies the specified range of the specified array into a new array. |
38 | This method copies the specified range of the specified array into a new array. |
39 | This method copies the specified range of the specified array into a new array. |
40 | This method copies the specified range of the specified array into a new array. |
41 | This method copies the specified range of the specified array into a new array. |
42 | This method copies the specified range of the specified array into a new array. |
43 | This method returns true if the two specified arrays are deeply equal to one another. |
44 | This method returns a hash code based on the "deep contents" of the specified array. |
45 | This method returns a string representation of the "deep contents" of the specified array. |
46 | This method returns true if the two specified arrays of booleans are equal to one another. |
47 | This method returns true if the two specified arrays of bytes are equal to one another. |
48 | This method returns true if the two specified arrays of chars are equal to one another. |
49 | This method returns true if the two specified arrays of double are equal to one another. |
50 | This method returns true if the two specified arrays of floats are equal to one another. |
51 | This method returns true if the two specified arrays of ints are equal to one another. |
52 | This method returns true if the two specified arrays of longs are equal to one another. |
53 | This method returns true if the two specified arrays of shorts are equal to one another. |
54 | This method returns true if the two specified arrays of Objects are equal to one another. |
55 | This method returns true if the two specified arrays of Objects are equal to one another. |
56 | This method assigns the specified boolean value to each element of the specified array of booleans. |
57 | This method assigns the specified byte value to each element of the specified array of bytes. |
58 | This method assigns the specified char value to each element of the specified array of chars. |
59 | This method assigns the specified double value to each element of the specified array of doubles. |
60 | This method assigns the specified float value to each element of the specified array of floats. |
61 | This method assigns the specified int value to each element of the specified array of ints. |
62 | This method assigns the specified long value to each element of the specified array of longs. |
63 | This method assigns the specified Object reference to each element of the specified array of Objects. |
64 | This method assigns the specified short value to each element of the specified array of shorts. |
65 | This method returns a hash code based on the contents of the specified array. |
66 | This method finds and returns the index of the first mismatch between two boolean arrays, otherwise return -1 if no mismatch is found. |
67 | This method finds and returns the index of the first mismatch between two byte arrays, otherwise return -1 if no mismatch is found. |
68 | This method finds and returns the index of the first mismatch between two char arrays, otherwise return -1 if no mismatch is found. |
69 | This method finds and returns the index of the first mismatch between two double arrays, otherwise return -1 if no mismatch is found. |
70 | This method finds and returns the index of the first mismatch between two int arrays, otherwise return -1 if no mismatch is found. |
71 | This method finds and returns the index of the first mismatch between two long arrays, otherwise return -1 if no mismatch is found. |
72 | This method finds and returns the index of the first mismatch between two short arrays, otherwise return -1 if no mismatch is found. |
73 | This method finds and returns the index of the first mismatch between two object arrays, otherwise return -1 if no mismatch is found. |
74 | This method finds and returns the index of the first mismatch between two object arrays, otherwise return -1 if no mismatch is found. |
75 | This method cumulates, in parallel, each element of the given array in place, using the supplied function. |
76 | This method cumulates, in parallel, each element of the given array in place, using the supplied function. |
77 | This method cumulates, in parallel, each element of the given array in place, using the supplied function. |
78 | This method cumulates, in parallel, each element of the given array in place, using the supplied function. |
79 | This method sets all elements of the specified array, in parallel, using the provided generator function to compute each element. |
80 | This method sets all elements of the specified array, in parallel, using the provided generator function to compute each element. |
81 | This method sets all elements of the specified array, in parallel, using the provided generator function to compute each element. |
82 | This method sets all elements of the specified array, in parallel, using the provided generator function to compute each element. |
83 | This method sorts the specified array of bytes into ascending numerical order. |
84 | This method sorts the specified array of chars into ascending numerical order. |
85 | This method sorts the specified array of doubles into ascending numerical order. |
86 | This method sorts the specified array of floats into ascending numerical order. |
87 | This method sorts the specified array of ints into ascending numerical order. |
88 | This method sorts the specified array of longs into ascending numerical order. |
89 | This method sorts the specified array of shorts into ascending numerical order. |
90 | This method sorts the specified array of objects into ascending order, according to the natural ordering of its elements. |
91 | This method sorts the specified array of objects into ascending order, according to the ordering provided by the Comparator instance. |
92 | This method sets all elements of the specified array, using the provided generator function to compute each element. |
93 | This method sets all elements of the specified array, using the provided generator function to compute each element. |
94 | This method sets all elements of the specified array, using the provided generator function to compute each element. |
95 | This method sets all elements of the specified array, using the provided generator function to compute each element. |
96 | This method returns a Spliterator.OfDouble covering all of the specified array. |
97 | This method returns a Spliterator.OfInt covering all of the specified array. |
98 | This method returns a Spliterator.OfLong covering all of the specified array. |
99 | This method returns a Spliterator covering all of the specified array. |
100 | This method returns a sequential DoubleStream with the specified array as its source. |
101 | This method returns a sequential IntStream with the specified array as its source. |
102 | This method returns a sequential LongStream with the specified array as its source. |
103 | This method returns a sequential Stream with the specified array as its source. |
104 | This method sorts the specified array of bytes into ascending numerical order. |
105 | This method sorts the specified array of chars into ascending numerical order. |
106 | This method sorts the specified array of doubles into ascending numerical order. |
107 | This method sorts the specified array of floats into ascending numerical order. |
108 | This method sorts the specified array of ints into ascending numerical order. |
109 | This method sorts the specified array of longs into ascending numerical order. |
110 | This method sorts the specified array of objects into ascending order, according to the natural ordering of its elements. |
111 | This method sorts the specified array of shorts into ascending numerical order. |
112 | This method sorts the specified array of objects according to the order induced by the specified comparator. |
113 | This method returns a string representation of the contents of the specified array of boolean. |
Methods Inherited
This class inherits methods from the following classes
- java.util.Object
Arrays Class Example
// Importing the Arrays classimport java.util.Arrays;
// Public Main Classpublic class Main { public static void main(String[] args) { // Declaring an array int arr[] = {8, 5, 3, 10, 2, 1, 15, 20};
// Sorting the array Arrays.sort(arr);
// Taking an element to search int ele = 15;
// Using binarySearch() method to search "ele" System.out.println( ele + " presents at the index = " + Arrays.binarySearch(arr, ele)); }}
Let us compile and run the above program, this will produce the following result
15 presents at the index = 6