Home » Tag Archives: linkedlist

Tag Archives: linkedlist

Search elements in LinkedList example

This is an example of how to search the elements in a LinkedList. Searching the elements in a LinkedList implies that you should: Create a new LinkedList. Populate the list with elements, with the add(E e) API method of the LinkedList. Invoke the contains(Object o) API method of LinkedList, to check if the list contains the specified object. It returns ...

Read More »

Replace element LinkedList example

In this example we shall show you how to replace an element in a LinkedList, that is setting another element in the index of that element. To replace an element in a LinkedList one should perform the following steps: Create a new LinkedList. Populate the list with elements, with the add(E e) API method of the LinkedLink. Invoke the set(int ...

Read More »

Remove element at index from LinkedList example

With this example we are going to demonstrate how to remove an element at a specific index from a LinkedList. In short, to remove an element at a specific index from a LinkedList you should: Create a new LinkedList. Populate the list with elements, with the add(E e) API method of the LinkedLink. Invoke the remove(int index) API method of ...

Read More »

Remove specific element from LinkedList example

This is an example of how to remove a specific element from a LinkedList in Java. Removing a specific element from a LinkedList implies that you should: Create a new LinkedList. Populate the list with elements, with the add(E e) API method of the LinkedLink. Invoke the remove(Object o) API method of the LinkedList. It will remove the first occurence ...

Read More »

Remove first and last element from LinkedList example

In this example we shall show you how to remove the first and the last element of a LinkedList. To remove the first and the last element of a LinkedList one should perform the following steps: Create a new LinkedList. Populate the list with elements, with the add(E e) API method of the LinkedLink. Invoke the removeFirst() API method of ...

Read More »

Remove all elements from LinkedList example

With this example we are going to demonstrate how to remove all elements from a LinkedList in Java. In short, to remove all elements from a LinkedList, that means clearing the list you should: Create a new LinkedList. Populate the list with elements, with the add(E e) API method of the LinkedLink. Invoke the clear() API method of the LinkedList. ...

Read More »

LinkedList ListIterator example

This is an example of how to obtain a LinkedList ListIterator. Using a LinkedList ListIterator implies that you should: Create a LinkedList. Populate the list with elements, with add(E e) API method. Obtain a ListIterator, using listIterator() method. For forward iteration over the collection elements invoke hasNext() and next() API methods of ListIterator. For backward iteration over the collection elements ...

Read More »

LinkedList Iterator example

In this example we shall show you how to obtain a LinkedList Iterator. The Iterator is used to remove elements from an underlying Collection. To obtain a LinkedList Iterator one should perform the following steps: Create a LinkedList. Populate the list with elements, with add(E e) API method. Obtain an Iterator, using iterator() method. Iterate over the elements of the ...

Read More »

Insert element at specific index in LinkedList example

With this example we are going to demonstrate how to insert an element at a specific index in a LinkedList. In short, to insert an element at a specific index in a LinkedList you should: Create a LinkedList. Populate the list with elements, with add(E e) API method. Invoke add(int index , Object element) API method of LinkedList. It inserts ...

Read More »

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 »