beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

Java – Get element from specific index of LinkedList example

By Chaitanya Singh | Filed Under: Java Collections

In this example we are gonna see how to get an element from specific index of LinkedList using get(int index) method:

public E get(int index): Returns the element at the specified position in this list.

import java.util.LinkedList;

public class GetElementExample {
 public static void main(String[] args) {
 
    // Creating LinkedList of String Elements
    LinkedList<String> linkedlist = new LinkedList<String>();
 
    // Populating it with String values
    linkedlist.add("AA");
    linkedlist.add("BB");
    linkedlist.add("CC");
    linkedlist.add("DD");
    linkedlist.add("EE");

    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));
    } 
 }
}

Output:

LinkedList Elements : 
Element at index 0 is: AA
Element at index 1 is: BB
Element at index 2 is: CC
Element at index 3 is: DD
Element at index 4 is: EE

Enjoyed this post? Try these related posts

  1. Difference between list set and map in java?
  2. Java – Get first and last elements from LinkedList example
  3. How to Set Vector size example
  4. Vector Enumeration example in Java
  5. Difference between HashMap and Hashtable
  6. Java ArrayList of Object Sort Example (Comparable And Comparator)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Java Tutorial

  • Java Tutorial
  • OOPs Concepts

Java Collections

  • ArrayList
  • LinkedList
  • ArrayList vs LinkedList
  • Vector
  • ArrayList vs Vector
  • HashMap
  • TreeMap
  • LinkedHashMap
  • HashSet
  • TreeSet
  • LinkedHashSet
  • Hashtable
  • HashMap vs Hashtable
  • Queue
  • PriorityQueue
  • Deque & ArrayDeque
  • Iterator
  • ListIterator
  • Comparable Interface
  • Comparator Interface
  • Java Collections Interview Q

MORE ...

  • Java String
  • Exception handling
  • Java Multithreading
  • Java I/O
  • Java Serialization
  • Java Regex
  • Java AWT
  • Java Swing
  • Java Enum
  • Java Annotations

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap