ArrayUtil { public static <T> T[] shuffle(T[] array) { if (array != null && array.length > 1) { Random rand = new Random(); return shuffle(array, rand); } else { return array; } }  @SuppressWarnings("unchecked") static T[] newArray(Class<T> type, int length); @SuppressWarnings("unchecked") static T[] toArray(Collection<T> col, Class<T> type); static T[] shuffle(T[] array); static T[] shuffle(T[] array, Random random); static T[] concat(@Nullable T element, T[] array); static T[] concat(T[] array, @Nullable T element); static List<T> asList(T... a); static List<Integer> intAsList(int... backingArray); static List<Long> longAsList(long... backingArray); static List<Double> doubleAsList(double... backingArray);  }
@Test public void shuffle() { String[] arrays = new String[] { "d", "a", "c", "b", "e", "i", "g" }; String[] arraysClone = Arrays.copyOf(arrays, arrays.length); Arrays.sort(arrays); assertThat(arrays).containsExactly("a", "b", "c", "d", "e", "g", "i"); ArrayUtil.shuffle(arrays); assertFalse("should not be equal to origin array", Arrays.equals(arrays, arraysClone)); Arrays.sort(arrays); ArrayUtil.shuffle(arrays, RandomUtil.secureRandom()); assertFalse("should not be equal to origin array", Arrays.equals(arrays, arraysClone)); }