Get Element at index Of Java LinkedList Example

Get Element at index Of Java LinkedList Example


Posted in : Java Posted on : November 29, 2010 at 5:23 PM Comments : [ 0 ]

This Java Example shows how to get an element at specified index in java LinkedList object.

Get Element at index Of Java LinkedList Example

This Java Example shows how to get an element at specified index in java LinkedList object. To get an element from specified index of LinkedList We use void get(int index) method. This method returns the element at the specified index of the LinkedList. 

 Example: getElementExample.java

package devmanuals.com;

import java.util.*;

public class getElementExample {
	public static void main(String[] args) {

		LinkedList LKLST = new LinkedList();
		LKLST.add("1");
		LKLST.add("2");
		LKLST.add("3");
		LKLST.add("4");
		System.out.println("The Linked List is as: " + LKLST);
		System.out.println("3rd Element : " + LKLST.get(2));
		System.out.println("4th Element  : " + LKLST.get(3));

	}
}

Output:

The Linked List is as: [1, 2, 3, 4] 

3rd Element : 3 

4th Element : 4

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics