Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
Public class StudentInfo {
String studentName;
String barrowedBooks;
String date;
String expiredDate;


void listOfStudent(){
  "How can i print all studentName in StudentInfo " 

}

}


Public class InputStudentInfo {

	StudentInfo studentReg, justin, gian;
		
		justin = new StudentInfo();
		gian = new StudentInfo();
		studentReg = new StudentInfo();
		
	
			
		justin.studentName = "Justin Lazaro";
		justin.barrowedBooks = ("English, Math");
		
		
		gian.studentName = "Gian Acuna";
		gian.barrowedBooks = "Math";
		
}
Posted
Updated 10-Nov-14 8:47am
v2

I'd suggest to use ArrayList[^].

Java
class InputStudentInfo {
 
    //
    public void main (String[] args)
    {
        //declare ArrayList to store students list
        ArrayList<studentInfo> students = new ArrayList<studentInfo>;

        StudentInfo student = new StudentInfo();
        //1
        student.studentName = "Justin Lazaro";
        student.barrowedBooks = ("English, Math");
        //add to list
        students.Add(student);     
        //2	
        student = new StudentInfo();
        student.studentName = "Gian Acuna";
        student.barrowedBooks = "Math";
        students.Add(student);
        //etc.

        //further...
        // use for(...) loop
        // to iterate through the collection of student
    }
}


For further information, please see: The for-each loop[^]

By The Way: Why do you declare date as as a string?
Java
String date;
String expiredDate;

Java knows date data type[^].
 
Share this answer
 
v2
Comments
Manas Bhardwaj 10-Nov-14 16:01pm    
yes +5!
Maciej Los 10-Nov-14 16:07pm    
Thank you, Manas ;)
Sergey Alexandrovich Kryukov 10-Nov-14 17:41pm    
...but no way ArrayList in .NET...
5ed.
—SA
Maciej Los 11-Nov-14 4:18am    
Thank you, Sergey ;)
Member 11111612 10-Nov-14 21:24pm    
for (int i=0; i< studentName.size(); i++){
System.out.println(studentName.get(i));

}



bro i cant print all value in arraylist
for (int i=0; i< studentName.size(); i++){
System.out.println(studentName.get(i));

}



bro i cant print all value in arraylist
 
Share this answer
 
Comments
Laiju k 10-Nov-14 22:46pm    
Don't put your comments in Solution

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