I found the code below from this SO question. It has worked great so far, but I have come across the need to shuffle arrays of strings. The code below only accepts arrays of ints as a parameter. I am still very new to java and I can't seem to figure out how to let the method accept multiple datatypes in it's parameters. It would be wonderful if I could use the same method to shuffle arrays of ints AND arrays of strings. Can anyone help?
static int[] shuffle(int[] ar) {
// If running on Java 6 or older, use `new Random()` on RHS here
Random rnd = ThreadLocalRandom.current();
for (int i = ar.length - 1; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
int a = ar[index];
ar[index] = ar[i];
ar[i] = a;
}
return ar;
}