Check to see if an object is an instance of a number in Java
Description
The following code shows how to check to see if an object is an instance of a number.
Example
/*from w w w.j a va 2 s. c om*/
import java.io.Serializable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Main {
public static boolean isNumber(final Object dataType) {
return Number.class.isInstance(dataType);
}
public static void main(final String[] args) {
System.out.println(isNumber("asdf"));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »