Home > Back-end >  , fill in here?
, fill in here?

Time:09-24

Define a set ArrayList object, add two student information, and print the output value of each element in the object in the set,
import java.util.ArrayList;
Import the Java. Util. Iterator;
Public class Test {
Public static void main (String [] args) {
Student s1=new Student (" 2016001 ", "zhang", "male", 21).
Student s2=new Student (" 2016002 ", "li si", "male", 22).
List List=new ArrayList (a);
List. Add (s1);
List. The add (s2);
Iterator It=..//access iterator
//judge whether there is any element
While (____________ hold) {
Student s=it. Next ();
String sno=s.g etSno ();
String name=s.g etName ();
String sex=s.g etSex ();
Int the age=s.g etAge ();
System. The out. Println (sno + "" + name +" "+ +" "+ age sex);
}
}
On the horizontal line to fill what?

CodePudding user response:

import java.util.ArrayList;
Import the Java. Util. Iterator;
Public class Test {
Public static void main (String [] args) {
Student s1=new Student (" 2016001 ", "zhang", "male", 21).
Student s2=new Student (" 2016002 ", "li si", "male", 22).
List List=new ArrayList (a);
List. Add (s1);
List. The add (s2);
Iterator It=list. The iterator ();//get the iterator
//judge whether there is any element
While ( it. HasNext () {
)Student s=it. Next ();
String sno=s.g etSno ();
String name=s.g etName ();
String sex=s.g etSex ();
Int the age=s.g etAge ();
System. The out. Println (sno + "" + name +" "+ +" "+ age sex);
}
}

CodePudding user response:

List. The iterator ();
It. HasNext ()
This question for baidu, post is too time consuming