public class objArrayPractice {
public static void main(String[] args) {
Object ar []= new Object [4];
ar[0]= 12;
}
}
when I write ar[0]= 12; I am getting the error: "Type mismatch: cannot convert from int to Object"
To convert 12 into an object you need al least Java 1.5, this is called Autoboxing
Autoboxing and unboxing was introduced in Java 1.5 to automatically convert primitive type into boxed primitive( Object or Wrapper class)
So be sure to have on both machines a Java version >= 1.5
int[] artoInteger[] ar. It will solve your issue.arelements should be objects and you supply it anint- it just doesn't know how to auto-box (either the JDK itself is too old or you set the source level to < 1.5) and thus it complains. ChangeartoInteger[]or usear[0] = Integer.valueOf(12);to make it work.