Class Arrays
public class Arrays extends Object
Arrays contains static methods which operate on arrays.- Since:
- 1.2
-
Method Summary
Modifier and Type Method Description static <T> List<T>asList(T... array)Returns aListof the objects in the specified array.static intbinarySearch(byte[] array, byte value)Performs a binary search forvaluein the ascending sorted arrayarray.static intbinarySearch(byte[] array, int startIndex, int endIndex, byte value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive).static intbinarySearch(char[] array, char value)Performs a binary search forvaluein the ascending sorted arrayarray.static intbinarySearch(char[] array, int startIndex, int endIndex, char value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive).static intbinarySearch(double[] array, double value)Performs a binary search forvaluein the ascending sorted arrayarray.static intbinarySearch(double[] array, int startIndex, int endIndex, double value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive).static intbinarySearch(float[] array, float value)Performs a binary search forvaluein the ascending sorted arrayarray.static intbinarySearch(float[] array, int startIndex, int endIndex, float value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive).static intbinarySearch(int[] array, int value)Performs a binary search forvaluein the ascending sorted arrayarray.static intbinarySearch(int[] array, int startIndex, int endIndex, int value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive).static intbinarySearch(long[] array, int startIndex, int endIndex, long value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive).static intbinarySearch(long[] array, long value)Performs a binary search forvaluein the ascending sorted arrayarray.static intbinarySearch(short[] array, int startIndex, int endIndex, short value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive).static intbinarySearch(short[] array, short value)Performs a binary search forvaluein the ascending sorted arrayarray.static intbinarySearch(Object[] array, int startIndex, int endIndex, Object value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive).static intbinarySearch(Object[] array, Object value)Performs a binary search forvaluein the ascending sorted arrayarray.static <T> intbinarySearch(T[] array, int startIndex, int endIndex, T value, Comparator<? super T> comparator)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive), usingcomparatorto compare elements.static <T> intbinarySearch(T[] array, T value, Comparator<? super T> comparator)Performs a binary search forvaluein the ascending sorted arrayarray, usingcomparatorto compare elements.static voidcheckOffsetAndCount(int arrayLength, int offset, int count)Checks that the range described byoffsetandcountdoesn't exceedarrayLength.static voidcheckStartAndEnd(int len, int start, int end)Checks that the range described bystartandenddoesn't exceedlen.static boolean[]copyOf(boolean[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array.static byte[]copyOf(byte[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array.static char[]copyOf(char[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array.static double[]copyOf(double[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array.static float[]copyOf(float[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array.static int[]copyOf(int[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array.static long[]copyOf(long[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array.static short[]copyOf(short[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array.static <T> T[]copyOf(T[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array.static <T, U> T[]copyOf(U[] original, int newLength, Class<? extends T[]> newType)CopiesnewLengthelements fromoriginalinto a new array.static boolean[]copyOfRange(boolean[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive).static byte[]copyOfRange(byte[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive).static char[]copyOfRange(char[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive).static double[]copyOfRange(double[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive).static float[]copyOfRange(float[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive).static int[]copyOfRange(int[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive).static long[]copyOfRange(long[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive).static short[]copyOfRange(short[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive).static <T> T[]copyOfRange(T[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive).static <T, U> T[]copyOfRange(U[] original, int start, int end, Class<? extends T[]> newType)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive).static booleandeepEquals(Object[] array1, Object[] array2)Returnstrueif the two given arrays are deeply equal to one another.static intdeepHashCode(Object[] array)Returns a hash code based on the "deep contents" of the given array.static StringdeepToString(Object[] array)Creates a "deep"Stringrepresentation of theObject[]passed, such that if the array contains other arrays, theStringrepresentation of those arrays is generated as well.static booleanequals(boolean[] array1, boolean[] array2)Compares the two arrays.static booleanequals(byte[] array1, byte[] array2)Compares the two arrays.static booleanequals(char[] array1, char[] array2)Compares the two arrays.static booleanequals(double[] array1, double[] array2)Compares the two arrays.static booleanequals(float[] array1, float[] array2)Compares the two arrays.static booleanequals(int[] array1, int[] array2)Compares the two arrays.static booleanequals(long[] array1, long[] array2)Compares the two arrays.static booleanequals(short[] array1, short[] array2)Compares the two arrays.static booleanequals(Object[] array1, Object[] array2)Compares the two arrays.static voidfill(boolean[] array, boolean value)Fills the specified array with the specified element.static voidfill(boolean[] array, int start, int end, boolean value)Fills the specified range in the array with the specified element.static voidfill(byte[] array, byte value)Fills the specified array with the specified element.static voidfill(byte[] array, int start, int end, byte value)Fills the specified range in the array with the specified element.static voidfill(char[] array, char value)Fills the specified array with the specified element.static voidfill(char[] array, int start, int end, char value)Fills the specified range in the array with the specified element.static voidfill(double[] array, double value)Fills the specified array with the specified element.static voidfill(double[] array, int start, int end, double value)Fills the specified range in the array with the specified element.static voidfill(float[] array, float value)Fills the specified array with the specified element.static voidfill(float[] array, int start, int end, float value)Fills the specified range in the array with the specified element.static voidfill(int[] array, int value)Fills the specified array with the specified element.static voidfill(int[] array, int start, int end, int value)Fills the specified range in the array with the specified element.static voidfill(long[] array, int start, int end, long value)Fills the specified range in the array with the specified element.static voidfill(long[] array, long value)Fills the specified array with the specified element.static voidfill(short[] array, int start, int end, short value)Fills the specified range in the array with the specified element.static voidfill(short[] array, short value)Fills the specified array with the specified element.static voidfill(Object[] array, int start, int end, Object value)Fills the specified range in the array with the specified element.static voidfill(Object[] array, Object value)Fills the specified array with the specified element.static inthashCode(boolean[] array)Returns a hash code based on the contents of the given array.static inthashCode(byte[] array)Returns a hash code based on the contents of the given array.static inthashCode(char[] array)Returns a hash code based on the contents of the given array.static inthashCode(double[] array)Returns a hash code based on the contents of the given array.static inthashCode(float[] array)Returns a hash code based on the contents of the given array.static inthashCode(int[] array)Returns a hash code based on the contents of the given array.static inthashCode(long[] array)Returns a hash code based on the contents of the given array.static inthashCode(short[] array)Returns a hash code based on the contents of the given array.static inthashCode(Object[] array)Returns a hash code based on the contents of the given array.static voidsort(byte[] array)Sorts the specified array in ascending numerical order.static voidsort(byte[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.static voidsort(char[] array)Sorts the specified array in ascending numerical order.static voidsort(char[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.static voidsort(double[] array)Sorts the specified array in ascending numerical order.static voidsort(double[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.static voidsort(float[] array)Sorts the specified array in ascending numerical order.static voidsort(float[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.static voidsort(int[] array)Sorts the specified array in ascending numerical order.static voidsort(int[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.static voidsort(long[] array)Sorts the specified array in ascending numerical order.static voidsort(long[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.static voidsort(short[] array)Sorts the specified array in ascending numerical order.static voidsort(short[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.static voidsort(Object[] array)Sorts the specified array in ascending natural order.static voidsort(Object[] array, int start, int end)Sorts the specified range in the array in ascending natural order.static <T> voidsort(T[] array, int start, int end, Comparator<? super T> comparator)Sorts the specified range in the array using the specifiedComparator.static <T> voidsort(T[] array, Comparator<? super T> comparator)Sorts the specified array using the specifiedComparator.static StringtoString(boolean[] array)Creates aStringrepresentation of theboolean[]passed.static StringtoString(byte[] array)Creates aStringrepresentation of thebyte[]passed.static StringtoString(char[] array)Creates aStringrepresentation of thechar[]passed.static StringtoString(double[] array)Creates aStringrepresentation of thedouble[]passed.static StringtoString(float[] array)Creates aStringrepresentation of thefloat[]passed.static StringtoString(int[] array)Creates aStringrepresentation of theint[]passed.static StringtoString(long[] array)Creates aStringrepresentation of thelong[]passed.static StringtoString(short[] array)Creates aStringrepresentation of theshort[]passed.static StringtoString(Object[] array)Creates aStringrepresentation of theObject[]passed.
-
Method Details
-
asList
Returns aListof the objects in the specified array. The size of theListcannot be modified, i.e. adding and removing are unsupported, but the elements can be set. Setting an element modifies the underlying array.- Parameters:
array- the array.- Returns:
- a
Listof the elements of the specified array.
-
binarySearch
public static int binarySearch(byte[] array, byte value)Performs a binary search forvaluein the ascending sorted arrayarray. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted.
-
binarySearch
public static int binarySearch(byte[] array, int startIndex, int endIndex, byte value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive). Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.startIndex- the inclusive start index.endIndex- the exclusive start index.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted. - Throws:
IllegalArgumentException- ifstartIndex > endIndexArrayIndexOutOfBoundsException- ifstartIndex < 0 || endIndex > array.length- Since:
- 1.6
-
binarySearch
public static int binarySearch(char[] array, char value)Performs a binary search forvaluein the ascending sorted arrayarray. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted.
-
binarySearch
public static int binarySearch(char[] array, int startIndex, int endIndex, char value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive). Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.startIndex- the inclusive start index.endIndex- the exclusive start index.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted. - Throws:
IllegalArgumentException- ifstartIndex > endIndexArrayIndexOutOfBoundsException- ifstartIndex < 0 || endIndex > array.length- Since:
- 1.6
-
binarySearch
public static int binarySearch(double[] array, double value)Performs a binary search forvaluein the ascending sorted arrayarray. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted.
-
binarySearch
public static int binarySearch(double[] array, int startIndex, int endIndex, double value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive). Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.startIndex- the inclusive start index.endIndex- the exclusive start index.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted. - Throws:
IllegalArgumentException- ifstartIndex > endIndexArrayIndexOutOfBoundsException- ifstartIndex < 0 || endIndex > array.length- Since:
- 1.6
-
binarySearch
public static int binarySearch(float[] array, float value)Performs a binary search forvaluein the ascending sorted arrayarray. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted.
-
binarySearch
public static int binarySearch(float[] array, int startIndex, int endIndex, float value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive). Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.startIndex- the inclusive start index.endIndex- the exclusive start index.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted. - Throws:
IllegalArgumentException- ifstartIndex > endIndexArrayIndexOutOfBoundsException- ifstartIndex < 0 || endIndex > array.length- Since:
- 1.6
-
binarySearch
public static int binarySearch(int[] array, int value)Performs a binary search forvaluein the ascending sorted arrayarray. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted.
-
binarySearch
public static int binarySearch(int[] array, int startIndex, int endIndex, int value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive). Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.startIndex- the inclusive start index.endIndex- the exclusive start index.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted. - Throws:
IllegalArgumentException- ifstartIndex > endIndexArrayIndexOutOfBoundsException- ifstartIndex < 0 || endIndex > array.length- Since:
- 1.6
-
binarySearch
public static int binarySearch(long[] array, long value)Performs a binary search forvaluein the ascending sorted arrayarray. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted.
-
binarySearch
public static int binarySearch(long[] array, int startIndex, int endIndex, long value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive). Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.startIndex- the inclusive start index.endIndex- the exclusive start index.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted. - Throws:
IllegalArgumentException- ifstartIndex > endIndexArrayIndexOutOfBoundsException- ifstartIndex < 0 || endIndex > array.length- Since:
- 1.6
-
binarySearch
Performs a binary search forvaluein the ascending sorted arrayarray. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted. - Throws:
ClassCastException- if an element in the array or the search element does not implementComparable, or cannot be compared to each other.
-
binarySearch
Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive). Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.startIndex- the inclusive start index.endIndex- the exclusive start index.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted. - Throws:
ClassCastException- if an element in the array or the search element does not implementComparable, or cannot be compared to each other.IllegalArgumentException- ifstartIndex > endIndexArrayIndexOutOfBoundsException- ifstartIndex < 0 || endIndex > array.length- Since:
- 1.6
-
binarySearch
Performs a binary search forvaluein the ascending sorted arrayarray, usingcomparatorto compare elements. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.value- the element to find.comparator- theComparatorused to compare the elements.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted. - Throws:
ClassCastException- if an element in the array or the search element does not implementComparable, or cannot be compared to each other.
-
binarySearch
public static <T> int binarySearch(T[] array, int startIndex, int endIndex, T value, Comparator<? super T> comparator)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive), usingcomparatorto compare elements. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.startIndex- the inclusive start index.endIndex- the exclusive start index.value- the element to find.comparator- theComparatorused to compare the elements.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted. - Throws:
ClassCastException- if an element in the array or the search element does not implementComparable, or cannot be compared to each other.IllegalArgumentException- ifstartIndex > endIndexArrayIndexOutOfBoundsException- ifstartIndex < 0 || endIndex > array.length- Since:
- 1.6
-
binarySearch
public static int binarySearch(short[] array, short value)Performs a binary search forvaluein the ascending sorted arrayarray. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted.
-
binarySearch
public static int binarySearch(short[] array, int startIndex, int endIndex, short value)Performs a binary search forvaluein the ascending sorted arrayarray, in the range specified by fromIndex (inclusive) and toIndex (exclusive). Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.- Parameters:
array- the sorted array to search.startIndex- the inclusive start index.endIndex- the exclusive start index.value- the element to find.- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted. - Throws:
IllegalArgumentException- ifstartIndex > endIndexArrayIndexOutOfBoundsException- ifstartIndex < 0 || endIndex > array.length- Since:
- 1.6
-
fill
public static void fill(byte[] array, byte value)Fills the specified array with the specified element.- Parameters:
array- thebytearray to fill.value- thebyteelement.
-
fill
public static void fill(byte[] array, int start, int end, byte value)Fills the specified range in the array with the specified element.- Parameters:
array- thebytearray to fill.start- the first index to fill.end- the last + 1 index to fill.value- thebyteelement.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
fill
public static void fill(short[] array, short value)Fills the specified array with the specified element.- Parameters:
array- theshortarray to fill.value- theshortelement.
-
fill
public static void fill(short[] array, int start, int end, short value)Fills the specified range in the array with the specified element.- Parameters:
array- theshortarray to fill.start- the first index to fill.end- the last + 1 index to fill.value- theshortelement.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
fill
public static void fill(char[] array, char value)Fills the specified array with the specified element.- Parameters:
array- thechararray to fill.value- thecharelement.
-
fill
public static void fill(char[] array, int start, int end, char value)Fills the specified range in the array with the specified element.- Parameters:
array- thechararray to fill.start- the first index to fill.end- the last + 1 index to fill.value- thecharelement.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
fill
public static void fill(int[] array, int value)Fills the specified array with the specified element.- Parameters:
array- theintarray to fill.value- theintelement.
-
fill
public static void fill(int[] array, int start, int end, int value)Fills the specified range in the array with the specified element.- Parameters:
array- theintarray to fill.start- the first index to fill.end- the last + 1 index to fill.value- theintelement.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
fill
public static void fill(long[] array, long value)Fills the specified array with the specified element.- Parameters:
array- thelongarray to fill.value- thelongelement.
-
fill
public static void fill(long[] array, int start, int end, long value)Fills the specified range in the array with the specified element.- Parameters:
array- thelongarray to fill.start- the first index to fill.end- the last + 1 index to fill.value- thelongelement.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
fill
public static void fill(float[] array, float value)Fills the specified array with the specified element.- Parameters:
array- thefloatarray to fill.value- thefloatelement.
-
fill
public static void fill(float[] array, int start, int end, float value)Fills the specified range in the array with the specified element.- Parameters:
array- thefloatarray to fill.start- the first index to fill.end- the last + 1 index to fill.value- thefloatelement.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
fill
public static void fill(double[] array, double value)Fills the specified array with the specified element.- Parameters:
array- thedoublearray to fill.value- thedoubleelement.
-
fill
public static void fill(double[] array, int start, int end, double value)Fills the specified range in the array with the specified element.- Parameters:
array- thedoublearray to fill.start- the first index to fill.end- the last + 1 index to fill.value- thedoubleelement.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
fill
public static void fill(boolean[] array, boolean value)Fills the specified array with the specified element.- Parameters:
array- thebooleanarray to fill.value- thebooleanelement.
-
fill
public static void fill(boolean[] array, int start, int end, boolean value)Fills the specified range in the array with the specified element.- Parameters:
array- thebooleanarray to fill.start- the first index to fill.end- the last + 1 index to fill.value- thebooleanelement.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
fill
Fills the specified array with the specified element.- Parameters:
array- theObjectarray to fill.value- theObjectelement.
-
fill
Fills the specified range in the array with the specified element.- Parameters:
array- theObjectarray to fill.start- the first index to fill.end- the last + 1 index to fill.value- theObjectelement.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
hashCode
public static int hashCode(boolean[] array)Returns a hash code based on the contents of the given array. For any twobooleanarraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List.hashCode()method which is invoked on aListcontaining a sequence ofBooleaninstances representing the elements of array in the same order. If the array isnull, the return value is 0.- Parameters:
array- the array whose hash code to compute.- Returns:
- the hash code for
array.
-
hashCode
public static int hashCode(int[] array)Returns a hash code based on the contents of the given array. For any two not-nullintarraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List.hashCode()method which is invoked on aListcontaining a sequence ofIntegerinstances representing the elements of array in the same order. If the array isnull, the return value is 0.- Parameters:
array- the array whose hash code to compute.- Returns:
- the hash code for
array.
-
hashCode
public static int hashCode(short[] array)Returns a hash code based on the contents of the given array. For any twoshortarraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List.hashCode()method which is invoked on aListcontaining a sequence ofShortinstances representing the elements of array in the same order. If the array isnull, the return value is 0.- Parameters:
array- the array whose hash code to compute.- Returns:
- the hash code for
array.
-
hashCode
public static int hashCode(char[] array)Returns a hash code based on the contents of the given array. For any twochararraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List.hashCode()method which is invoked on aListcontaining a sequence ofCharacterinstances representing the elements of array in the same order. If the array isnull, the return value is 0.- Parameters:
array- the array whose hash code to compute.- Returns:
- the hash code for
array.
-
hashCode
public static int hashCode(byte[] array)Returns a hash code based on the contents of the given array. For any twobytearraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List.hashCode()method which is invoked on aListcontaining a sequence ofByteinstances representing the elements of array in the same order. If the array isnull, the return value is 0.- Parameters:
array- the array whose hash code to compute.- Returns:
- the hash code for
array.
-
hashCode
public static int hashCode(long[] array)Returns a hash code based on the contents of the given array. For any twolongarraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List.hashCode()method which is invoked on aListcontaining a sequence ofLonginstances representing the elements of array in the same order. If the array isnull, the return value is 0.- Parameters:
array- the array whose hash code to compute.- Returns:
- the hash code for
array.
-
hashCode
public static int hashCode(float[] array)Returns a hash code based on the contents of the given array. For any twofloatarraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List.hashCode()method which is invoked on aListcontaining a sequence ofFloatinstances representing the elements of array in the same order. If the array isnull, the return value is 0.- Parameters:
array- the array whose hash code to compute.- Returns:
- the hash code for
array.
-
hashCode
public static int hashCode(double[] array)Returns a hash code based on the contents of the given array. For any twodoublearraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List.hashCode()method which is invoked on aListcontaining a sequence ofDoubleinstances representing the elements of array in the same order. If the array isnull, the return value is 0.- Parameters:
array- the array whose hash code to compute.- Returns:
- the hash code for
array.
-
hashCode
Returns a hash code based on the contents of the given array. If the array contains other arrays as its elements, the hash code is based on their identities not their contents. So it is acceptable to invoke this method on an array that contains itself as an element, either directly or indirectly.For any two arrays
aandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the method Arrays.asList(array).hashCode(). If the array is
null, the return value is 0.- Parameters:
array- the array whose hash code to compute.- Returns:
- the hash code for
array.
-
deepHashCode
Returns a hash code based on the "deep contents" of the given array. If the array contains other arrays as its elements, the hash code is based on their contents not their identities. So it is not acceptable to invoke this method on an array that contains itself as an element, either directly or indirectly.For any two arrays
aandb, ifArrays.deepEquals(a, b)returnstrue, it means that the return value ofArrays.deepHashCode(a)equalsArrays.deepHashCode(b).The computation of the value returned by this method is similar to that of the value returned by
List.hashCode()invoked on aListcontaining a sequence of instances representing the elements of array in the same order. The difference is: If an element e of array is itself an array, its hash code is computed by calling the appropriate overloading ofArrays.hashCode(e)if e is an array of a primitive type, or by callingArrays.deepHashCode(e)recursively if e is an array of a reference type. The value returned by this method is the same value as the methodArrays.asList(array).hashCode(). If the array isnull, the return value is 0.- Parameters:
array- the array whose hash code to compute.- Returns:
- the hash code for
array.
-
equals
public static boolean equals(byte[] array1, byte[] array2)Compares the two arrays.- Parameters:
array1- the firstbytearray.array2- the secondbytearray.- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
equals
public static boolean equals(short[] array1, short[] array2)Compares the two arrays.- Parameters:
array1- the firstshortarray.array2- the secondshortarray.- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
equals
public static boolean equals(char[] array1, char[] array2)Compares the two arrays.- Parameters:
array1- the firstchararray.array2- the secondchararray.- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
equals
public static boolean equals(int[] array1, int[] array2)Compares the two arrays.- Parameters:
array1- the firstintarray.array2- the secondintarray.- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
equals
public static boolean equals(long[] array1, long[] array2)Compares the two arrays.- Parameters:
array1- the firstlongarray.array2- the secondlongarray.- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
equals
public static boolean equals(float[] array1, float[] array2)Compares the two arrays. The values are compared in the same manner asFloat.equals().- Parameters:
array1- the firstfloatarray.array2- the secondfloatarray.- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.- See Also:
Float.equals(Object)
-
equals
public static boolean equals(double[] array1, double[] array2)Compares the two arrays. The values are compared in the same manner asDouble.equals().- Parameters:
array1- the firstdoublearray.array2- the seconddoublearray.- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.- See Also:
Double.equals(Object)
-
equals
public static boolean equals(boolean[] array1, boolean[] array2)Compares the two arrays.- Parameters:
array1- the firstbooleanarray.array2- the secondbooleanarray.- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
equals
Compares the two arrays.- Parameters:
array1- the firstObjectarray.array2- the secondObjectarray.- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal according toequals(),falseotherwise.
-
deepEquals
Returnstrueif the two given arrays are deeply equal to one another. Unlike the methodequals(Object[] array1, Object[] array2), this method is appropriate for use for nested arrays of arbitrary depth.Two array references are considered deeply equal if they are both
null, or if they refer to arrays that have the same length and the elements at each index in the two arrays are equal.Two
nullelementselement1andelement2are possibly deeply equal if any of the following conditions satisfied:element1andelement2are both arrays of object reference types, andArrays.deepEquals(element1, element2)would returntrue.element1andelement2are arrays of the same primitive type, and the appropriate overloading ofArrays.equals(element1, element2)would returntrue.element1 == element2element1.equals(element2)would returntrue.Note that this definition permits
nullelements at any depth.If either of the given arrays contain themselves as elements, the behavior of this method is uncertain.
- Parameters:
array1- the firstObjectarray.array2- the secondObjectarray.- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal according toequals(),falseotherwise.
-
sort
public static void sort(byte[] array)Sorts the specified array in ascending numerical order.- Parameters:
array- thebytearray to be sorted.
-
sort
public static void sort(byte[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.- Parameters:
array- thebytearray to be sorted.start- the start index to sort.end- the last + 1 index to sort.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
checkOffsetAndCount
public static void checkOffsetAndCount(int arrayLength, int offset, int count)Checks that the range described byoffsetandcountdoesn't exceedarrayLength. -
checkStartAndEnd
public static void checkStartAndEnd(int len, int start, int end)Checks that the range described bystartandenddoesn't exceedlen. -
sort
public static void sort(char[] array)Sorts the specified array in ascending numerical order.- Parameters:
array- thechararray to be sorted.
-
sort
public static void sort(char[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.- Parameters:
array- thechararray to be sorted.start- the start index to sort.end- the last + 1 index to sort.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
sort
public static void sort(double[] array)Sorts the specified array in ascending numerical order.- Parameters:
array- thedoublearray to be sorted.- See Also:
sort(double[], int, int)
-
sort
public static void sort(double[] array, int start, int end)Sorts the specified range in the array in ascending numerical order. The values are sorted according to the order imposed byDouble.compareTo().- Parameters:
array- thedoublearray to be sorted.start- the start index to sort.end- the last + 1 index to sort.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.- See Also:
Double.compareTo(Double)
-
sort
public static void sort(float[] array)Sorts the specified array in ascending numerical order.- Parameters:
array- thefloatarray to be sorted.- See Also:
sort(float[], int, int)
-
sort
public static void sort(float[] array, int start, int end)Sorts the specified range in the array in ascending numerical order. The values are sorted according to the order imposed byFloat.compareTo().- Parameters:
array- thefloatarray to be sorted.start- the start index to sort.end- the last + 1 index to sort.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.- See Also:
Float.compareTo(Float)
-
sort
public static void sort(int[] array)Sorts the specified array in ascending numerical order.- Parameters:
array- theintarray to be sorted.
-
sort
public static void sort(int[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.- Parameters:
array- theintarray to be sorted.start- the start index to sort.end- the last + 1 index to sort.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
sort
public static void sort(long[] array)Sorts the specified array in ascending numerical order.- Parameters:
array- thelongarray to be sorted.
-
sort
public static void sort(long[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.- Parameters:
array- thelongarray to be sorted.start- the start index to sort.end- the last + 1 index to sort.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
sort
public static void sort(short[] array)Sorts the specified array in ascending numerical order.- Parameters:
array- theshortarray to be sorted.
-
sort
public static void sort(short[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.- Parameters:
array- theshortarray to be sorted.start- the start index to sort.end- the last + 1 index to sort.- Throws:
IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
sort
Sorts the specified array in ascending natural order.- Throws:
ClassCastException- if any element does not implementComparable, or ifcompareTothrows for any pair of elements.
-
sort
Sorts the specified range in the array in ascending natural order.- Parameters:
start- the start index to sort.end- the last + 1 index to sort.- Throws:
ClassCastException- if any element does not implementComparable, or ifcompareTothrows for any pair of elements.IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
sort
Sorts the specified range in the array using the specifiedComparator. All elements must be comparable to each other without aClassCastExceptionbeing thrown.- Parameters:
start- the start index to sort.end- the last + 1 index to sort.comparator- theComparator.- Throws:
ClassCastException- if elements in the array cannot be compared to each other using the givenComparator.IllegalArgumentException- ifstart > end.ArrayIndexOutOfBoundsException- ifstart < 0orend > array.length.
-
sort
Sorts the specified array using the specifiedComparator. All elements must be comparable to each other without aClassCastExceptionbeing thrown.- Throws:
ClassCastException- if elements in the array cannot be compared to each other using theComparator.
-
toString
Creates aStringrepresentation of theboolean[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString.valueOf(boolean)and separated by", ". If the array isnull, then"null"is returned.- Parameters:
array- thebooleanarray to convert.- Returns:
- the
Stringrepresentation ofarray. - Since:
- 1.5
-
toString
Creates aStringrepresentation of thebyte[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString.valueOf(int)and separated by", ". If the array isnull, then"null"is returned.- Parameters:
array- thebytearray to convert.- Returns:
- the
Stringrepresentation ofarray. - Since:
- 1.5
-
toString
Creates aStringrepresentation of thechar[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString.valueOf(char)and separated by", ". If the array isnull, then"null"is returned.- Parameters:
array- thechararray to convert.- Returns:
- the
Stringrepresentation ofarray. - Since:
- 1.5
-
toString
Creates aStringrepresentation of thedouble[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString.valueOf(double)and separated by", ". If the array isnull, then"null"is returned.- Parameters:
array- thedoublearray to convert.- Returns:
- the
Stringrepresentation ofarray. - Since:
- 1.5
-
toString
Creates aStringrepresentation of thefloat[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString.valueOf(float)and separated by", ". If the array isnull, then"null"is returned.- Parameters:
array- thefloatarray to convert.- Returns:
- the
Stringrepresentation ofarray. - Since:
- 1.5
-
toString
Creates aStringrepresentation of theint[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString.valueOf(int)and separated by", ". If the array isnull, then"null"is returned.- Parameters:
array- theintarray to convert.- Returns:
- the
Stringrepresentation ofarray. - Since:
- 1.5
-
toString
Creates aStringrepresentation of thelong[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString.valueOf(long)and separated by", ". If the array isnull, then"null"is returned.- Parameters:
array- thelongarray to convert.- Returns:
- the
Stringrepresentation ofarray. - Since:
- 1.5
-
toString
Creates aStringrepresentation of theshort[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString.valueOf(int)and separated by", ". If the array isnull, then"null"is returned.- Parameters:
array- theshortarray to convert.- Returns:
- the
Stringrepresentation ofarray. - Since:
- 1.5
-
toString
Creates aStringrepresentation of theObject[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString.valueOf(Object)and separated by", ". If the array isnull, then"null"is returned.- Parameters:
array- theObjectarray to convert.- Returns:
- the
Stringrepresentation ofarray. - Since:
- 1.5
-
deepToString
Creates a "deep"Stringrepresentation of theObject[]passed, such that if the array contains other arrays, theStringrepresentation of those arrays is generated as well.If any of the elements are primitive arrays, the generation is delegated to the other
toStringmethods in this class. If any element contains a reference to the original array, then it will be represented as"[...]". If an element is anObject[], then its representation is generated by a recursive call to this method. All other elements are converted via theString.valueOf(Object)method.- Parameters:
array- theObjectarray to convert.- Returns:
- the
Stringrepresentation ofarray. - Since:
- 1.5
-
copyOf
public static boolean[] copyOf(boolean[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array. IfnewLengthis greater thanoriginal.length, the result is padded with the valuefalse.- Parameters:
original- the original arraynewLength- the length of the new array- Returns:
- the new array
- Throws:
NegativeArraySizeException- ifnewLength < 0NullPointerException- iforiginal == null- Since:
- 1.6
-
copyOf
public static byte[] copyOf(byte[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array. IfnewLengthis greater thanoriginal.length, the result is padded with the value(byte) 0.- Parameters:
original- the original arraynewLength- the length of the new array- Returns:
- the new array
- Throws:
NegativeArraySizeException- ifnewLength < 0NullPointerException- iforiginal == null- Since:
- 1.6
-
copyOf
public static char[] copyOf(char[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array. IfnewLengthis greater thanoriginal.length, the result is padded with the value'\\u0000'.- Parameters:
original- the original arraynewLength- the length of the new array- Returns:
- the new array
- Throws:
NegativeArraySizeException- ifnewLength < 0NullPointerException- iforiginal == null- Since:
- 1.6
-
copyOf
public static double[] copyOf(double[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array. IfnewLengthis greater thanoriginal.length, the result is padded with the value0.0d.- Parameters:
original- the original arraynewLength- the length of the new array- Returns:
- the new array
- Throws:
NegativeArraySizeException- ifnewLength < 0NullPointerException- iforiginal == null- Since:
- 1.6
-
copyOf
public static float[] copyOf(float[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array. IfnewLengthis greater thanoriginal.length, the result is padded with the value0.0f.- Parameters:
original- the original arraynewLength- the length of the new array- Returns:
- the new array
- Throws:
NegativeArraySizeException- ifnewLength < 0NullPointerException- iforiginal == null- Since:
- 1.6
-
copyOf
public static int[] copyOf(int[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array. IfnewLengthis greater thanoriginal.length, the result is padded with the value0.- Parameters:
original- the original arraynewLength- the length of the new array- Returns:
- the new array
- Throws:
NegativeArraySizeException- ifnewLength < 0NullPointerException- iforiginal == null- Since:
- 1.6
-
copyOf
public static long[] copyOf(long[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array. IfnewLengthis greater thanoriginal.length, the result is padded with the value0L.- Parameters:
original- the original arraynewLength- the length of the new array- Returns:
- the new array
- Throws:
NegativeArraySizeException- ifnewLength < 0NullPointerException- iforiginal == null- Since:
- 1.6
-
copyOf
public static short[] copyOf(short[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array. IfnewLengthis greater thanoriginal.length, the result is padded with the value(short) 0.- Parameters:
original- the original arraynewLength- the length of the new array- Returns:
- the new array
- Throws:
NegativeArraySizeException- ifnewLength < 0NullPointerException- iforiginal == null- Since:
- 1.6
-
copyOf
public static <T> T[] copyOf(T[] original, int newLength)CopiesnewLengthelements fromoriginalinto a new array. IfnewLengthis greater thanoriginal.length, the result is padded with the valuenull.- Parameters:
original- the original arraynewLength- the length of the new array- Returns:
- the new array
- Throws:
NegativeArraySizeException- ifnewLength < 0NullPointerException- iforiginal == null- Since:
- 1.6
-
copyOf
CopiesnewLengthelements fromoriginalinto a new array. IfnewLengthis greater thanoriginal.length, the result is padded with the valuenull.- Parameters:
original- the original arraynewLength- the length of the new arraynewType- the class of the new array- Returns:
- the new array
- Throws:
NegativeArraySizeException- ifnewLength < 0NullPointerException- iforiginal == nullArrayStoreException- if a value inoriginalis incompatible with T- Since:
- 1.6
-
copyOfRange
public static boolean[] copyOfRange(boolean[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive). The original order of elements is preserved. Ifendis greater thanoriginal.length, the result is padded with the valuefalse.- Parameters:
original- the original arraystart- the start index, inclusiveend- the end index, exclusive- Returns:
- the new array
- Throws:
ArrayIndexOutOfBoundsException- ifstart < 0 || start > original.lengthIllegalArgumentException- ifstart > endNullPointerException- iforiginal == null- Since:
- 1.6
-
copyOfRange
public static byte[] copyOfRange(byte[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive). The original order of elements is preserved. Ifendis greater thanoriginal.length, the result is padded with the value(byte) 0.- Parameters:
original- the original arraystart- the start index, inclusiveend- the end index, exclusive- Returns:
- the new array
- Throws:
ArrayIndexOutOfBoundsException- ifstart < 0 || start > original.lengthIllegalArgumentException- ifstart > endNullPointerException- iforiginal == null- Since:
- 1.6
-
copyOfRange
public static char[] copyOfRange(char[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive). The original order of elements is preserved. Ifendis greater thanoriginal.length, the result is padded with the value'\\u0000'.- Parameters:
original- the original arraystart- the start index, inclusiveend- the end index, exclusive- Returns:
- the new array
- Throws:
ArrayIndexOutOfBoundsException- ifstart < 0 || start > original.lengthIllegalArgumentException- ifstart > endNullPointerException- iforiginal == null- Since:
- 1.6
-
copyOfRange
public static double[] copyOfRange(double[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive). The original order of elements is preserved. Ifendis greater thanoriginal.length, the result is padded with the value0.0d.- Parameters:
original- the original arraystart- the start index, inclusiveend- the end index, exclusive- Returns:
- the new array
- Throws:
ArrayIndexOutOfBoundsException- ifstart < 0 || start > original.lengthIllegalArgumentException- ifstart > endNullPointerException- iforiginal == null- Since:
- 1.6
-
copyOfRange
public static float[] copyOfRange(float[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive). The original order of elements is preserved. Ifendis greater thanoriginal.length, the result is padded with the value0.0f.- Parameters:
original- the original arraystart- the start index, inclusiveend- the end index, exclusive- Returns:
- the new array
- Throws:
ArrayIndexOutOfBoundsException- ifstart < 0 || start > original.lengthIllegalArgumentException- ifstart > endNullPointerException- iforiginal == null- Since:
- 1.6
-
copyOfRange
public static int[] copyOfRange(int[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive). The original order of elements is preserved. Ifendis greater thanoriginal.length, the result is padded with the value0.- Parameters:
original- the original arraystart- the start index, inclusiveend- the end index, exclusive- Returns:
- the new array
- Throws:
ArrayIndexOutOfBoundsException- ifstart < 0 || start > original.lengthIllegalArgumentException- ifstart > endNullPointerException- iforiginal == null- Since:
- 1.6
-
copyOfRange
public static long[] copyOfRange(long[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive). The original order of elements is preserved. Ifendis greater thanoriginal.length, the result is padded with the value0L.- Parameters:
original- the original arraystart- the start index, inclusiveend- the end index, exclusive- Returns:
- the new array
- Throws:
ArrayIndexOutOfBoundsException- ifstart < 0 || start > original.lengthIllegalArgumentException- ifstart > endNullPointerException- iforiginal == null- Since:
- 1.6
-
copyOfRange
public static short[] copyOfRange(short[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive). The original order of elements is preserved. Ifendis greater thanoriginal.length, the result is padded with the value(short) 0.- Parameters:
original- the original arraystart- the start index, inclusiveend- the end index, exclusive- Returns:
- the new array
- Throws:
ArrayIndexOutOfBoundsException- ifstart < 0 || start > original.lengthIllegalArgumentException- ifstart > endNullPointerException- iforiginal == null- Since:
- 1.6
-
copyOfRange
public static <T> T[] copyOfRange(T[] original, int start, int end)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive). The original order of elements is preserved. Ifendis greater thanoriginal.length, the result is padded with the valuenull.- Parameters:
original- the original arraystart- the start index, inclusiveend- the end index, exclusive- Returns:
- the new array
- Throws:
ArrayIndexOutOfBoundsException- ifstart < 0 || start > original.lengthIllegalArgumentException- ifstart > endNullPointerException- iforiginal == null- Since:
- 1.6
-
copyOfRange
public static <T, U> T[] copyOfRange(U[] original, int start, int end, Class<? extends T[]> newType)Copies elements fromoriginalinto a new array, from indexes start (inclusive) to end (exclusive). The original order of elements is preserved. Ifendis greater thanoriginal.length, the result is padded with the valuenull.- Parameters:
original- the original arraystart- the start index, inclusiveend- the end index, exclusive- Returns:
- the new array
- Throws:
ArrayIndexOutOfBoundsException- ifstart < 0 || start > original.lengthIllegalArgumentException- ifstart > endNullPointerException- iforiginal == nullArrayStoreException- if a value inoriginalis incompatible with T- Since:
- 1.6
-