Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi,i weant example for array of class please :/
Posted
Updated 12-Sep-22 3:08am
Comments
[no name] 26-Dec-15 11:15am    
Google for it!
Sergey Alexandrovich Kryukov 26-Dec-15 11:29am    
This is re-post. Please, don't re-post; it's considered as abuse. You did not reply to any comments on the page of your original post.
—SA

Courtesy of Google, Java - Arrays[^]
 
Share this answer
 
Please, see my past answer: Making Contact Management System[^]

I'd suggest there to use ArrayList instead of array. ArrayList is more powerful then array, because provides simple way to manage the size of array!
 
Share this answer
 
v2
This array can hold 3 objects (CAPACITY).
CURRENT POSITION is where you are going to add your object.

You could try something similar.

public void addStudent(Student student) {
    if (CURRENT_POSITION < CAPACITY) {
        students[CURRENT_POSITION] = student;
        CURRENT_POSITION++;
    }
}
 
Share this answer
 
Comments
CHill60 12-Sep-22 9:42am    
Reason for my downvote - You haven't really added anything new to this 7 year old thread. Also without explaining that student is an object which is an instance of the class Student you haven't even attempted to answer the OP's question.
Are CURRENT_POSITION and CAPACITY global variables or internal properties of the class? Where does this routine "live".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900