Skip to content

Instantly share code, notes, and snippets.

@tedheich
Created November 18, 2009 12:11
Show Gist options
  • Save tedheich/237775 to your computer and use it in GitHub Desktop.
Save tedheich/237775 to your computer and use it in GitHub Desktop.
Array examples for creating Java Objects
class ArrayEx {
public static void main(String []args) {
Object obj[] = new Object[3];
for (int i=0;i < obj.length; i++ ) {
if (obj[i] instanceof Object) {
System.out.println("obj[" + i + "] = Object" );
}
else {
System.out.println("obj[" + i + "] <> Object");
}
}
}
}
class ArrayEx2 {
public static void main(String []args) {
Object obj[] = new Object[3];
for (int j=0; j < obj.length ; j++) {
obj[j] = new Object();
}
for (int i=0;i < obj.length; i++ ) {
if (obj[i] instanceof Object) {
System.out.println("obj[" + i + "] = Object" );
}
else {
System.out.println("obj[" + i + "] <> Object");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment