Online Java Compiler By
JavaTpoint.com
import java.util.Iterator; import java.util.concurrent.LinkedTransferQueue; class Student { static int i = 1; public String name; public String college; String rollNo; Student(String rollNo, String college, String name) { this.rollNo= rollNo; this.name = name; this.college= college; } public String toString() { return i++ + ".Roll No. = " + this.rollNo+ "\n College = " + this.college+ "\n Name = " + this.name + "\n"; } } public class LinkedTransferQueueIteratorExample2 { static int i=1; public static void main(String[] args) { Student student1 = new Student("15cs1029", "AKTU University", "Harry"); Student student2 = new Student("15cs1010", "CCS University", "Johnson"); Student student3 = new Student("17cs1029", "MR University", "Marry"); Student student4 = new Student("15cs1011", "MVN University", "Jack"); LinkedTransferQueue
queue = new LinkedTransferQueue
(); queue.add(student1); queue.add(student2); queue.add(student3); queue.add(student4); Iterator
iterator = queue.iterator(); //Returns an iterator over the elements while (iterator.hasNext()) { System.out.println(i++ + "." + iterator.next()); } } }
Output