File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes An array of objects???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "An array of objects????" Watch "An array of objects????" New topic

An array of objects????

Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
Hi people.

Let's say i have to create a student object - say student name, id and phone number. Is it possible to create an array of these student objects?

Moosey knows best
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

Ofcourse. See the tutorial: Arrays

[ October 25, 2006: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

You can create an array of references to Students; just as normal variables are just references to objects, array elements are, too. So when you construct an array of Student it will contain all null Student references. If you want to construct a Student for each position in the array, then could use a loop to do that:

More likely you'd have a file containing Student data, and you read it in a loop and construct Student objects based on the data.

[Jess in Action][AskingGoodQuestions]
Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
Thanks guys - very helpful
I agree. Here's the link:
subject: An array of objects????
It's not a secret anymore!