I would like to be able to take in any array type as a parameter in a method.:
public void foo(Array[] array) {
System.out.println(array.length)
}
Well, you can do something like this (because an array is an Object) -
public static int getArrayLength(Object array) {
return Array.getLength(array);
}
public static void main(String[] args) {
int[] intArray = { 1, 2, 3 };
String[] stringArray = { "1", "2", "c", "d" };
System.out.println(getArrayLength(intArray));
System.out.println(getArrayLength(stringArray));
}
Output is
3
4