Online Java Compiler By
JavaTpoint.com
import java.util.LinkedList; import java.util.List; public class JavaListGetExample3 { public static void main(String[] args) { List
list= new LinkedList<>(); list.add(5); list.add(56); list.add(509); // throws an exception if the index is out of range i.e. index<0 or index>=size() int index =list.get(-1); System.out.println("Element "+-1+" stored at Index : "+index); } }
Output