aspose file tools
The moose likes Beginning Java and the fly likes An array of objects???? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 188
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
Bartender

Joined: Aug 16, 2005
Posts: 12921
    
    3

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: 24057
    
  13

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: 188
Thanks guys - very helpful
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: An array of objects????
 
Similar Threads
Arrays
newbie simple java program
array variables out of scope-why?
Regarding JAXB 1.3
Creating array of objects from user input and saving to a file