java.lang.Object
org.jgrapht.util.ArrayUtil
Utility class to simplify handling of arrays.
- Author:
- Hannes Wellmann
-
Method Summary
Modifier and TypeMethodDescriptionstatic final voidreverse(int[] arr, int from, int to) Reverses the order of the elements in the specified range within the given array.static final <V> voidreverse(V[] arr, int from, int to) Reverses the order of the elements in the specified range within the given array.static voidswap(double[] arr, int i, int j) Swaps the two elements at the specified indices in the given double array.static voidswap(int[] arr, int i, int j) Swaps the two elements at the specified indices in the given int array.static final <V> voidswap(V[] arr, int i, int j) Swaps the two elements at the specified indices in the given array.
-
Method Details
-
reverse
public static final <V> void reverse(V[] arr, int from, int to) Reverses the order of the elements in the specified range within the given array.- Type Parameters:
V- the type of elements in the array- Parameters:
arr- the arrayfrom- the index of the first element (inclusive) inside the range to reverseto- the index of the last element (inclusive) inside the range to reverse- Throws:
NullPointerException- ifarr == nullArrayIndexOutOfBoundsException- if either one offromortois out of bounds
-
reverse
public static final void reverse(int[] arr, int from, int to) Reverses the order of the elements in the specified range within the given array.- Parameters:
arr- the arrayfrom- the index of the first element (inclusive) inside the range to reverseto- the index of the last element (inclusive) inside the range to reverse- Throws:
NullPointerException- ifarr == nullArrayIndexOutOfBoundsException- if either one offromortois out of bounds
-
swap
public static final <V> void swap(V[] arr, int i, int j) Swaps the two elements at the specified indices in the given array.- Type Parameters:
V- the type of elements in the array- Parameters:
arr- the arrayi- the index of the first elementj- the index of the second element- Throws:
NullPointerException- ifarr == nullArrayIndexOutOfBoundsException- if either one ofiorjis out of bounds
-
swap
public static void swap(double[] arr, int i, int j) Swaps the two elements at the specified indices in the given double array.- Parameters:
arr- the arrayi- the index of the first elementj- the index of the second element- Throws:
NullPointerException- ifarr == nullArrayIndexOutOfBoundsException- if either one ofiorjis out of bounds- Since:
- 1.5.3
-
swap
public static void swap(int[] arr, int i, int j) Swaps the two elements at the specified indices in the given int array.- Parameters:
arr- the arrayi- the index of the first elementj- the index of the second element- Throws:
NullPointerException- ifarr == nullArrayIndexOutOfBoundsException- if either one ofiorjis out of bounds- Since:
- 1.5.3
-