Home » Core Java » util » LinkedList (page 2)

LinkedList

Obtain sub List from LinkedList example

This is an example of how to obtain a subList of a LinkedList, that is a view to a specified range of the list. Getting a sublist of a LinkedList implies that you should: Create a new LinkedList. Populate the list with elements, with add(E e) API method of LinkedList. Invoke the subList(int fromIndex, int toIndex) API method of LinkedList. ...

Read More »

Get first and last elements in LinkedList example

In this example we shall show you how to get the first and the last elements of a LinkedList. The LinkedList class provides methods for these operations. To get the first and the last elements of a LinkedList one should perform the following steps: Create a new LinkedList. Populate the list with elements, with add(E e) API method of LinkedList. ...

Read More »

Get element at specific index of LinkedList example

With this example we are going to demonstrate how to get an element at a specific index of a LinkedList. The LinkedList API provides methods to do such operations. In short, to get an element of a LinkedList, giving an index as parameter you should: Create a new LinkedList. Populate the list with elements, with add(E e) API method of ...

Read More »

Convert LinkedList to Object array example

This is an example of how to convert a LinkedList to an Object array. Converting a LinkedList to an array implies that you should: Create a new LinkedList. Populate the list with elements, with add(E e) API method of LinkedList. Get an array containing all of the elements in this list in proper sequence (from first to last element), using ...

Read More »

Check for element existence in LinkedList example

In this example we shall show you how to check if an element exists in a LinkedList or not. To check an element existence in a LinkedList one should perform the following steps: Create a new LinkedList. Populate the list with elements, with add(E e) API method of LinkedList. Check if an element exists in the list, with contains(Object o) ...

Read More »

Add elements at the beginning and end of LinkedList example

With this example we are going to demonstrate how to add elements in the start and the end of a LinkedList. The LinkedList API provides methods to do such operations. In short, to add elements in the start and the end of a LinkedList you should: Create a new LinkedList. Populate the list with elements, with add(E e) API method ...

Read More »