wood burning stoves 2.0*
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
Author

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: 14074
    
  16

Ofcourse. See the tutorial: Arrays

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

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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: http://aspose.com/file-tools
 
subject: An array of objects????
 
Similar Threads
array variables out of scope-why?
newbie simple java program
Arrays
Regarding JAXB 1.3
Creating array of objects from user input and saving to a file