Java - Get Element From Specific Index Of LinkedList
Chapter:
Data Structures
Last Updated:
05-09-2016 16:27:08 UTC
Program:
/* ............... START ............... */
import java.util.LinkedList;
public class JavaGetElementFromSpecificIndexLinkedList {
public static void main(String[] args) {
// Creating LinkedList of String Elements
LinkedList<String> linkedlist = new LinkedList<String>();
// Populating it with String values
linkedlist.add("Harry");
linkedlist.add("Tom");
linkedlist.add("Steve");
linkedlist.add("Mark");
linkedlist.add("Joy");
System.out.println("LinkedList Elements : ");
// get(i) returns element present at index i
for (int i = 0; i < linkedlist.size(); i++) {
System.out.println("Element at index " + i + " is: " + linkedlist.get(i));
}
}
}
/* ............... END ............... */
Output
LinkedList Elements :
Element at index 0 is: Harry
Element at index 1 is: Tom
Element at index 2 is: Steve
Element at index 3 is: Mark
Element at index 4 is: Joy
Notes:
-
public get(int index): Returns the element at the specified position in this list.
Tags
Get Element From Specific Index Of LinkedList, Java