Please help me complete my isEmpty method:
public static boolean isEmpty(Object test){
if (test==null){
return true;
}
if (test.getClass().isArray()){
//???
}
if (test instanceof String){
String s=(String)test;
return s=="";
}
if (test instanceof Collection){
Collection c=(Collection)test;
return c.size()==0;
}
return false;
}
What code would I put int to establish that if I am dealing with an array it will return true if it’s length is zero? I want it to work no matter the type whether it is int[], Object[]. (Just so you know, I can tell you that if you put an int[] into an Object[] variable, it will throw an exception.)
You can use the helper method
getLength(Object)fromjava.reflect.Array:Note that you can’t use
because that is not safe. For comparing strings, use
String.equals(String), or in this case, just check if the length is zero.