Learn to program the Java Tutorial Object array published, welcome to visit through the xuebiancheng8.com
What is an array of objects, an array of objects, as the name implies.
First define an object
public class student{
Private String username;
private String password;
Setter,getter ....
}
As shown above, a student object is defined
3 Student objects to join now what do we do?
Student stu1 = new Student ();
Student STU2 = new Student ();
Student stu3 = new Student ();
Instantiate the above three objects.
If there are now 100 objects to do, it is not necessary to instantiate 100 objects, so it is too troublesome, this time you can use the object array
Student [] stu = new student[100];
There are 100 student in this array.
If you put a student in the first place, you can do this.
Stu[0] = new Student ();
If you put a student in the second position, you can do this.
STU[1] = new Student ();
If it's in the third position,
STU[2] = new Student ();
When the assignment is complete, you can
STU[0] subscript to access.
This time is the same as the usage of ordinary arrays.
For more information, please visit xuebiancheng8.com.
The specific URL is
Http://xuebiancheng8.com/play/goodgoodstudy_126_daydayup.html
An array of objects to learn Java tutorials