Getting Component type

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.

Getting Component type

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