The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Learning the Java Language
Lesson: Object Basics and Simple Data Objects

Arrays of Objects

Arrays can hold reference types as well as primitive types. You create such an array in much the same way you create an array with primitive types. Here's a small program, ArrayOfStringsDemo (in a .java source file) that creates an array containing three string objects then prints the strings in all lower case letters.
public class ArrayOfStringsDemo {
    public static void main(String[] args) {
        String[] anArray = { "String One", 
                             "String Two", 
                             "String Three" };

        for (String s: anArray) {
            System.out.println(s.toLowerCase());
        }
    }
}
The output from this program is
string one
string two
string three

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.