Iterating through an Object Array


package edu.training.object;

public class ArrayObject {

      public static void main(String[] args) {
     
            Object[] myObjects = {
                        new Integer(12),
                        new String("foo"),
                        new Integer(5),
                        new Boolean(true)
            };
           
            for (Object o: myObjects) {
                  System.out.println(o);
                 
            }

      }

}

Output:
12
foo
5
true

No comments: