How can I know the instance of java.util.Arrays$ArrayList
. I\'ve tried this code snippet but it does not work at all :
if (myList instanceof Arrays)
java.util.Arrays$ArrayList
is a private inner class of Arrays
, returned by the Arrays.asList
method.
Since it's a private class there is no way to get access to the class in a way that it can be used with the instanceof
operator. You can do this check using reflection however:
Class> clazz = Class.forName("java.util.Arrays$ArrayList");
// ...
clazz.isAssignableFrom(myList)
But I do not recommend doing that. It's a good practice to program against an interface. In this case the List interface defines the behavior of the object. The actual class of the object shouldn't matter.