Getting array class name

I have a problem I.

In the method, I get the shared object as a parameter, and I need to get the class name

public void myMethod(Object o) String className = o.getClass().getName(); ... } 

This works, unless I give arrays of methods. For example, if the method pass is an array of double ( double[] ), getClass().getName() returns me [D

How can I get something like double[] ?

+7
source share
3 answers

[D means an array of doubles. Check this link for an explanation of class names. Why do you need something like double[] instead?

+12
source

The simple class name is what you are looking for:

 System.out.print(new String[0].getClass().getSimpleName()); 

and the result will be as follows:

 String[] 
+2
source

If you give use of a wrapper class, you get ' [Ljava.lang.Double '

 Double[] d = new Double[10] 

d.getClass (). getName () gives you [Ljava.lang.Double

+1
source

All Articles