Getting Component type

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

Ads

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

Ads
Share on Google+Share on Google+

Getting Component type

Posted on: September 10, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Getting Component type  

Post your Comment


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

Ads

 

Ads