Home Java Reflect Getting Component type



Getting Component type
Posted on: September 10, 2008 at 12:00 AM
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

Related Tags for Getting Component type:
ccomarrayiointegertypecomponentintthiselementifforieexampletoexameilitsectionlscantriepeinnomnttrcaretrieveemmehowxaxampssoatkishallmplrayarssrithavhatlsopleplonomo


More Tutorials from this section

Ask Questions?    Discuss: Getting Component type  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.