Can we Store Heterogeneous Data in array
class array
{
public static void main(String[] args)
{
int i='c';
int[] a=new int[10] ; // integer type array
a[0]=100; // store integer value
a[1]='a'; // store character value
System.out.println("Result "+a[1]);
System.out.println("Result of i "+i);
}
}
Output:
Explanations:
Here in first case i am storing character value in integer type variable and in second case i am storing character value in integer type array,
But these all are possible only due to auto boxing, before jdk 1.5 version this is not possible but after jdk 1.5 auto boxing concept is there so this is possible.
we can also see here result of character is in integer format (ASCII value of a).
we already discuss about auto boxing.