Home Java Reflect Getting Component type

Related Tutorials


 
 

Share on Google+Share on Google+

Getting Component type

Advertisement
In this section you will come to know that how you can retrieve Component Type of an array's element.

Getting Component type

     

In this section you will come to know that how you can retrieve Component Type of an array's element. The component type of an Array is the type of array's element. For example if we have an integer type array then its component type will also be integer.

Here is the example code of ComponentType class :

ComponentType.java

import java.lang.reflect.*;

public class ComponentType {
  public static void main(String str[]){
  int[] intvar = {1,2,3,4};
 double[] doublevar = {1.0,2.2,3.5,4.8};
 Class intcls= intvar.getClass();
 Class doublecls= doublevar.getClass();
    System.out.println(" \"intvar\" component type => "
  +intcls.getComponentType
());
   System.out.println(" \"doublevar\" cpmponent type => "
  
+doublecls.getComponentType());
  }
}

To run this example create and save ComponentType.java and compile it. After compilation execute ComponentType.class file.

 Output

Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 10, 2008

Related Tutorials

Discuss: Getting Component type  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com