Online Java Compiler By
JavaTpoint.com
import java.util.LinkedList; import java.util.List; import java.util.ListIterator; class Student{ String name; String school; Student(String name, String school){ this.name=name; this.school=school; } public String toString() { return " Name : "+this.name+" School : "+this.school; } } public class JavaListSizeExample2 { public static void main(String[] args) { List
list = new LinkedList<>(); Student s1= new Student("Reema","Gita Convent School"); Student s2= new Student("Geetu","Gita Convent School"); Student s3= new Student("Saloni","Eicher School"); list.add(s1); list.add(s2); list.add(s3); //returns the total number of students in the list System.out.println("Total students : "+list.size()); for (Student val : list){ System.out.println(val); } } }
Output