tk.hongkailiu.test.app.util.ArrayUtil Maven / Gradle / Ivy
The newest version!
package tk.hongkailiu.test.app.util;
public class ArrayUtil {
public static void swapItemsAt(T[] array, int i, int j) {
if (array == null || array.length < 2) {
return;
}
if (array.length - 1 < Math.max(i, j)) {
throw new IllegalArgumentException(
"array.length -1: " + (array.length - 1) + " is smaller than max(i,j)" + Math
.max(i, j));
}
if (i != j) {
T temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy