How to get element of LinkedList

This article shows how to get elements from LinkedList Java . In this article we get element from specific index of LinkedList in java using LinkedList get() method.

How to get element of LinkedList Java Example

Java linked list get element by index using LinkedList get() method.This method returns the element at the specified position in this list. Now we will see  how to get element from specific index of LinkedList java.

import java.util.LinkedList;

public class GetElement {

public static void main(String[] args) {

LinkedList<String> linkedList = new LinkedList<String>();

linkedList.add("Mumbai");
linkedList.add("Delhi");
linkedList.add("Noida");
linkedList.add("Gao");
linkedList.add("Patna");

//print linkedlist
System.out.println("Before Remove Element Linklist is = "+linkedList);

System.out.println("Element At Index 2 ="+linkedList.get(2));

}

}

Output:

Before Remove Element Linklist is = [Mumbai, Delhi, Noida, Gao, Patna]

Element At Index 2 =Noida

We have discussed  Java LinkedList get element by index examples in this articles.

A Guide to ArrayList

Leave a Reply

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

52 − = 46