"Hi, Amigo!"
"How was your morning lesson?"
"Well, it was decent. I'll tell you about it."
"Bilaabo gave me a bunch of design patterns, and Ellie showed me a whole bunch of collections. Not an easy day after all."
"Don't you worry — I won't burden you with very much."
"I want to tell you about the two utility classes that you've already encountered."
"The Arrays and Collections classes. All their methods are static and designed to work with collections and arrays."
"I'll start with the simpler one: Arrays. Here are its methods:"
Methods | Explanation |
---|---|
|
Returns an immutable list filled with the passed elements. |
|
Searches for an element (key) in array a or the subarray from fromIndex to toIndex. The array must be sorted! Returns the element index, or fromIndex-1 if the element is not found. |
|
Returns a copy of the original array, starting from the zeroth index and consisting of newLength elements. |
|
Returns a copy of the original array, from 'from' to 'to'. |
|
Performs a deep comparison of two arrays. Arrays are considered equal if their elements are equal. If the elements themselves are arrays, then a deep comparison is also performed on them. |
|
Returns a deep hashcode based on all of the elements. If an element is an array, then deepHashCode is also called on the element. |
|
Performs a deep conversion of an array to a string. Calls toString() on every element. If an element is an array, then it is also converted to a string based on its deep contents. |
|
Compares two arrays element by element. |
|
Fills an array (or subarray) with the specified value. |
|
Computes the total hash code of all elements of an array. |
|
Sorts an array (or subarray) in ascending order. |
|
Converts an array to a string. Calls toString() on every element; |
"Well, these are very useful methods. Many would be helpful to me."
I'd also like to mention that I haven't presented all of the methods here. Almost all of the methods in the table have identical counterparts for all the primitive types. For example, the table has a String toString(int[] a) method, and the class also has String toString(boolean[] a), String toString(byte[] a), String toString(long[] a), String toString(float[] a), String toString(double[] a), and String toString(char[] a) methods."
"Well, that changes things. That makes it a simply indispensable class."
"I'm glad you liked it. Well, we'll continue after a break."
GO TO FULL VERSION