Example of LinkedList in Java
June 09, 2013
java.util.LinkedList is the implementation of List. The main feature of LinkedList is that it allows removing and inserting at end, start and end. LinkedList allows null values for all indexes. LinkedList also implements Deque. Find the example.
LinkedListDemo.java
package com.concretepage.util; import java.util.LinkedList; import java.util.List; public class LinkedListDemo { public static void main(String[] args) { List<String> lnkList = new LinkedList<String>(); //add the element at the end lnkList.add("A"); //add the element at the specified index. lnkList.add(0,"B"); //replace the element at the specified index lnkList.set(1,"C"); //get value by index System.out.println(lnkList.get(1)); //iterate LinkedList for(String s:lnkList){ System.out.println(s); } } }