aspose file tools
The moose likes Beginning Java and the fly likes How to know if type is array or not Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How to know if type is array or not " Watch "How to know if type is array or not " New topic
Author

How to know if type is array or not

Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
im getting from method the parameters types

Class[] types = currentMethod.getParameterTypes();

now i like to know if types[i] is array or not
if i do : types[j].getName() im getting only the type name but no indication if its array or not

how can i do that ?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

"types[i]" is an instance of java.lang.Class. Did you look carefully at the Javadocs for this class? For example, are there any methods with "array" in their names that look promising?


[Jess in Action][AskingGoodQuestions]
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
Hi sorry i meant how to know if its 2 dimensional array
simple case to know if its array i will use isArray
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

In Java "2D arrays" are actually arrays of arrays. The Class.getComponentType() method tells you the type of the data an array can hold; for a "2D array", this will be another array type. So something like



Of course, this also returns true for "3D", "4D", etc, arrays.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to know if type is array or not
 
Similar Threads
get method args types
Method.invoke()
Using String
copying file into database
Help with displaying data in JTextfield