Yandex

Java Advanced ConceptsJava Advanced Concepts3

Java LinkedList Methods Reference



add()
public boolean add(E e)
public void add(int index, E element)
Adds an element to the end or inserts it at a specified position.
addAll()
public boolean addAll(Collection c)
public boolean addAll(int index, Collection c)
Adds all elements from a collection, optionally at a specific index.
addFirst()
public void addFirst(E e)
Inserts the element at the beginning of the list.
addLast()
public void addLast(E e)
Appends the element to the end of the list.
clear()
public void clear()
Removes all elements, making the list empty.
clone()
public Object clone()
Returns a shallow copy of the LinkedList instance.
contains()
public boolean contains(Object o)
Checks if a specific element exists in the list.
descendingIterator()
public Iterator descendingIterator()
Returns an iterator that iterates the list in reverse order.
element()
public E element()
Retrieves, but does not remove, the head of the list.
get()
public E get(int index)
Returns the element at the specified index.
getFirst()
public E getFirst()
Retrieves the first element without removing it.
getLast()
public E getLast()
Retrieves the last element without removing it.
indexOf()
public int indexOf(Object o)
Returns the index of the first occurrence of the element.
lastIndexOf()
public int lastIndexOf(Object o)
Returns the index of the last occurrence of the element.
listIterator()
public ListIterator listIterator(int index)
Returns a list iterator starting at the specified position.
offer()
public boolean offer(E e)
Inserts the specified element at the end of the list.
offerFirst()
public boolean offerFirst(E e)
Inserts the element at the front of the list.
offerLast()
public boolean offerLast(E e)
Adds the element at the end of the list.
peek()
public E peek()
Retrieves the head of the list without removing it.
peekFirst()
public E peekFirst()
Retrieves the first element without removal.
peekLast()
public E peekLast()
Retrieves the last element without removal.
poll()
public E poll()
Retrieves and removes the head of the list.
pollFirst()
public E pollFirst()
Retrieves and removes the first element of the list.
pollLast()
public E pollLast()
Retrieves and removes the last element of the list.
pop()
public E pop()
Pops an element from the stack represented by the list.
push()
public void push(E e)
Pushes an element onto the stack represented by the list.
remove()
public E remove()
public E remove(int index)
public boolean remove(Object o)
Removes and returns the first element or removes a specified element or index.
removeFirst()
public E removeFirst()
Removes and returns the first element.
removeFirstOccurrence()
public boolean removeFirstOccurrence(Object o)
Removes the first occurrence of the specified element.
removeLast()
public E removeLast()
Removes and returns the last element.
removeLastOccurrence()
public boolean removeLastOccurrence(Object o)
Removes the last occurrence of the specified element.
set()
public E set(int index, E element)
Replaces the element at the specified position.
size()
public int size()
Returns the number of elements in the list.
spliterator()
public Spliterator spliterator()
Creates a late-binding and fail-fast Spliterator.
toArray()
public Object[] toArray()
public  T[] toArray(T[] a)
Returns an array containing all elements of the list.


Welcome to ProgramGuru

Sign up to start your journey with us

Support ProgramGuru.org

You can support this website with a contribution of your choice.

When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.

PayPal

UPI

PhonePe QR

MALLIKARJUNA M