Consider a method whose signature contains an Integer Array:
public static void parse(Integer[] categories)
parse needs to call a different method, which expects an Array of Strings. So I need to convert Integer[] to String[].
For example, [31, 244] ⇒ ["31", "244"].
I’ve tried Arrays.copyOf described here:
String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class);
But got an ArrayStoreException.
I can iterate and convert each element, but is there a more elegant way?
If you’re not trying to avoid a loop then you can simply do:
EDIT: I admit this is a hack but it works without iterating the original Integer array: