In the java language arrays are primitive. Collections are not.
Since a set is unordered it has no way to understand how to build an ordered array from a hashed set of memory locations.
When you output a set you are calling the toString method on that set.
So:
When I call
Integer[] selects = (Integer[]) tbl_analytes.getValue();
I get the following error:
Caused by: java.lang.ClassCastException: java.util.Collections$UnmodifiableSet cannot be cast to [Ljava.lang.Integer;
But when I do this:
Object obj = tbl_analytes.getValue();
System.out.println(obj);
I get the following output
[1,7,15]
The reason is Integer[]
is completely uncastable from Set<Integer>
but
the output from toString
is derived from:
The java.util.Collections$UnmodifiableSet extends java.util.AbstractCollection
https://docs.oracle.com/javase/10/docs/api/java/util/AbstractCollection.html#toString()
Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String.valueOf(Object).
That is the resason you are getting the exception. The solution to it is answered here in this stack overflow question:
How to convert Set<String> to String[]?