Online Java Compiler By
JavaTpoint.com
import java.util.LinkedList; import java.util.List; class Information { String idNo, name; int age; public Information(String idNo, String name, int age) { this.idNo= idNo; this.name = name; this.age= age; } public String toString(){ return "ID : "+idNo+"\nName : "+name+"\nAge : "+age; } } public class JavaListGetExample2 { static int i = 1; public static void main(String[] args) { List
list = new LinkedList<>(); Information val1 = new Information("15", "Reema panda", 21); Information val2 = new Information("16", "Geetanjali Sharma", 21); Information val3 = new Information("17", "Ajeet Kumar", 36); list.add(val1); list.add(val2); list.add(val3); //will get the value at index 2 Information index=list.get(2); System.out.println(index); } }
Output