0% found this document useful (0 votes)
3 views2 pages

Java Arrays Methods Descriptions Examples

Uploaded by

aravindharun03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java Arrays Methods Descriptions Examples

Uploaded by

aravindharun03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Arrays Class Methods - Descriptions & Examples

Java Arrays Class Methods - Descriptions & Examples

1. toString(array)
- Description: Returns a string representation of the array.
- Example:
int[] arr = {1, 2, 3};
String result = Arrays.toString(arr); // "[1, 2, 3]"

2. sort(array)
- Description: Sorts the specified array into ascending order.
- Example:
Arrays.sort(arr); // arr becomes [1, 2, 3]

3. copyOf(array, newLength)
- Description: Copies the original array to a new array of the specified length.
- Example:
int[] newArr = Arrays.copyOf(arr, 5);

4. copyOfRange(array, from, to)


- Description: Copies a specified range from the original array.
- Example:
int[] subArr = Arrays.copyOfRange(arr, 1, 3);

5. fill(array, value)
- Description: Fills the array with the specified value.
- Example:
Arrays.fill(arr, 0); // All elements become 0

6. equals(arr1, arr2)
- Description: Compares two arrays for equality.
- Example:
boolean isEqual = Arrays.equals(arr1, arr2);

7. deepEquals(arr1, arr2)
- Description: Compares nested arrays for equality.
- Example:
boolean isDeepEqual = Arrays.deepEquals(nested1, nested2);

8. binarySearch(array, key)
- Description: Searches the array for the specified value (must be sorted).
- Example:
int index = Arrays.binarySearch(arr, 3);

9. mismatch(arr1, arr2)
- Description: Finds and returns the index of the first mismatch between two arrays.
- Example:
int mismatchIndex = Arrays.mismatch(arr1, arr2);

10. parallelSort(array)
- Description: Sorts the array using parallel sorting.
- Example:
Arrays.parallelSort(arr);

11. stream(array)
- Description: Returns a sequential stream from the array.
- Example:
Arrays.stream(arr).forEach(System.out::println);

12. setAll(array, IntUnaryOperator)


- Description: Sets each element using a generator function.
- Example:
Arrays.setAll(arr, i -> i * i);

You might also like