Which of the following is a proper implementation for a method that displays the
ID: 3895102 • Letter: W
Question
Which of the following is a proper implementation for a method that displays the contents of a List?
(a)
public void Di splayRos t e r ( Li s t<Student> r o s t e r ) {
I t e r a t o r <Student> i t e r = r o s t e r . i t e r a t o r ( ) ;
while ( i t e r . hasNext ( ) )
System . out . p r i n t l n ( i t e r . next ( ) ) ;
}
public void Di splayRos t e r ( Li s t<Student> r o s t e r ) {
I t e r a t o r <Student> i t e r = r o s t e r . i t e r a t o r ( ) ;
while ( i t e r . Next ( ) != nul l )
System . out . p r i n t l n ( i t e r . next ( ) ) ;
}
(b)
public void Di splayRos t e r ( Li s t<Student> r o s t e r ) {
I t e r a t o r <Student> i t e r = r o s t e r . i t e r a t o r ( ) ;
while ( i t e r . hasNext ( ) )
System . out . p r i n t l n ( i t e r . getNext ( ) ) ;
}
public void Di splayRos t e r ( Li s t<Student> r o s t e r ) {
I t e r a t o r <Student> i t e r = r o s t e r . g e t I t e r a t o r ( ) ;
while ( i t e r . hasNext ( ) )
System . out . p r i n t l n ( i t e r . next ( ) ) ;
}
Explanation / Answer
If you have any doubts, please give me comment...
Ans: a)
public void DisplayRoster(List<Student> roster) {
Iterator<Student> iter = roster.iterator();
while (iter.hasNext())
System.out.println(iter.next());
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.