GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.tutorialspoint.com — Java LinkedList Class
Selected Reading
Java LinkedList ClassIntroductionThe Java LinkedList class operations perform we can expect for a doubly-linked list. Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index. Class declarationFollowing is the declaration for java.util.LinkedList class − public class LinkedList<E> extends AbstractSequentialList<E> implements List<E>, Deque<E>, Cloneable, Serializable ParametersFollowing is the parameter for java.util.LinkedList class − E − This is the type of elements held in this collection. FieldFields inherited from class java.util.AbstractList. Class constructors
Class methods
Methods inheritedThis class inherits methods from the following classes −
Adding element to a LinkedList ExampleThe following example shows the usage of Java LinkedList add(E) method to add Integers. We're adding couple of Integers to the LinkedList object using add() method calls per element and then print each element to show the elements added. package com.tutorialspoint;
import java.util.LinkedList;
public class LinkedListDemo {
public static void main(String[] args) {
// create an empty linked list
LinkedList<Integer> linkedList = new LinkedList<>();
// use add() method to add elements in the linkedList
linkedList.add(20);
linkedList.add(30);
linkedList.add(20);
linkedList.add(30);
linkedList.add(15);
linkedList.add(22);
linkedList.add(11);
// let us print all the elements available in linkedList
for (Integer number : linkedList) {
System.out.println("Number = " + number);
}
}
}
OutputLet us compile and run the above program, this will produce the following result − Number = 20 Number = 30 Number = 20 Number = 30 Number = 15 Number = 22 Number = 11 Advertisements
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |