1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
/* Get elements from LinkedList Java example This java example shows how to get element at specified index from Java LinkedList using get method. */ import java.util.LinkedList; public class GetElementsLinkedListExample { public static void main(String[] args) { //create LinkedList object LinkedList lList = new LinkedList(); //add elements to LinkedList lList.add("1"); lList.add("2"); lList.add("3"); lList.add("4"); lList.add("5"); /* * To get element at specified index from Java LinkedList, use * Object get(int index) method. * * This method returns element at sepcified index from LinkedList. */ System.out.println("LinkedList contains : "); for(int i=0; i< lList.size(); i++) { System.out.println(lList.get(i)); } } } /* Output would be LinkedList contains : 1 2 3 4 5 */ |
Add Comment