Its All Binary
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
FRAME | NO FRAME | TREE

Package java.util

Class java.util.LinkedList

Examples for usage of all methods of 'java.util.LinkedList' with console output of example code.

Methods

Please click on method from below list to go to code example for usage of that method. Click [↓ Imports] to get import statements used in examples. To read javadoc of methods, click on [⿺ Javadoc] for that method.

Method Examples

public boolean add(E arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("item-0");
        linkedList.add("item-1");
        //Output the list
        System.out.println("list values = " + linkedList);

        //Adding few more items in the list
        linkedList.add("item-2");
        linkedList.add("item-3");
        //New list
        System.out.println("list values after adding few more items = " + linkedList);

        linkedList.add(null);
        linkedList.add(null);
        // Nulls are allowed to add in linked list
        System.out.println("list values after adding null = " + linkedList);
    
					
Output:
list values = [item-0, item-1]
list values after adding few more items = [item-0, item-1, item-2, item-3]
list values after adding null = [item-0, item-1, item-2, item-3, null, null]

Tag: Example for add method of class java.util.LinkedList., LinkedList add function example with arguments E arg0, How to use add method of LinkedList?, Usage of LinkedList.add, LinkedList.add() examples

public void add(int arg0, E arg1)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();

        linkedList.add(0, "item-0");
        linkedList.add(1, "item-1");
        linkedList.add(2, "item-2");
        //Output the list
        System.out.println("list values = " + linkedList);

        linkedList.add(1, "item-new-1");
        //Repalce item at given index
        System.out.println("list values = " + linkedList);

        linkedList.add(1,null);
        linkedList.add(2,null);

        //Nulls are allowed to add in linked list
        System.out.println("list values = " + linkedList);
    
					
Output:
list values = [item-0, item-1, item-2]
list values = [item-0, item-new-1, item-1, item-2]
list values = [item-0, null, null, item-new-1, item-1, item-2]

Tag: Example for add method of class java.util.LinkedList., LinkedList add function example with arguments int arg0, E arg1, How to use add method of LinkedList?, Usage of LinkedList.add, LinkedList.add() examples

public boolean addAll(int arg0, java.util.Collection<? extends E> arg1)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList linkedList = new LinkedList();
        linkedList.add(0, "item-0");
        linkedList.add(1, "item-1");
        linkedList.add(2, "item-2");
        //Output first list
        System.out.println("list values = " + linkedList);

        LinkedList otherlinkedList = new LinkedList();
        otherlinkedList.add(0, "other-item-0");
        otherlinkedList.add(1, "other-item-1");
        //Output second list
        System.out.println("list values = " + otherlinkedList);

        linkedList.addAll(1,otherlinkedList);
        System.out.println("list values after adding at index 1 = " + linkedList);
    
					
Output:
list values = [item-0, item-1, item-2]
list values = [other-item-0, other-item-1]
list values after adding at index 1 = [item-0, other-item-0, other-item-1, item-1, item-2]

Tag: Example for addAll method of class java.util.LinkedList., LinkedList addAll function example with arguments int arg0, java.util.Collection<? extends E> arg1, How to use addAll method of LinkedList?, Usage of LinkedList.addAll, LinkedList.addAll() examples

public boolean addAll(java.util.Collection<? extends E> arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        //Output the first list
        System.out.println("list values = " + linkedList);

        LinkedList<String> otherlinkedList = new LinkedList<>();
        otherlinkedList.add("other-item-0");
        otherlinkedList.add("other-item-1");
        otherlinkedList.add("other-item-2");
        //Output the second list
        System.out.println("list other values = " + otherlinkedList);

        linkedList.addAll(otherlinkedList);
        System.out.println("list after adding = " + linkedList);
    
					
Output:
list values = [item-0, item-1, item-2]
list other values = [other-item-0, other-item-1, other-item-2]
list after adding = [item-0, item-1, item-2, other-item-0, other-item-1, other-item-2]

Tag: Example for addAll method of class java.util.LinkedList., LinkedList addAll function example with arguments java.util.Collection<? extends E> arg0, How to use addAll method of LinkedList?, Usage of LinkedList.addAll, LinkedList.addAll() examples

public void addFirst(E arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        //Output the list
        System.out.println("list values = " + linkedList);

        //Adding new elements at the beginning
        linkedList.addFirst("first-item-0");
        linkedList.addFirst("first-item-1");
        //Output the new list
        System.out.println("list values = " + linkedList);
    
					
Output:
list values = [item-0, item-1, item-2]
list values = [first-item-1, first-item-0, item-0, item-1, item-2]

Tag: Example for addFirst method of class java.util.LinkedList., LinkedList addFirst function example with arguments E arg0, How to use addFirst method of LinkedList?, Usage of LinkedList.addFirst, LinkedList.addFirst() examples

public void addLast(E arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        //Output the list
        System.out.println("list values = " + linkedList);

        //Adding new elements at the last
        linkedList.addLast("last-item-0");
        linkedList.addLast("last-item-1");
        //Output the new list
        System.out.println("list values = " + linkedList);
    
					
Output:
list values = [item-0, item-1, item-2]
list values = [item-0, item-1, item-2, last-item-0, last-item-1]

Tag: Example for addLast method of class java.util.LinkedList., LinkedList addLast function example with arguments E arg0, How to use addLast method of LinkedList?, Usage of LinkedList.addLast, LinkedList.addLast() examples

public void clear()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        //Output the list
        System.out.println("list values = " + linkedList);

        //Clear the list
        linkedList.clear();
        System.out.println("list after clear = " + linkedList);
    
					
Output:
list values = [item-0, item-1, item-2]
list after clear = []

Tag: Example for clear method of class java.util.LinkedList., LinkedList clear function example , How to use clear method of LinkedList?, Usage of LinkedList.clear, LinkedList.clear() examples

public java.lang.Object clone()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        //Output the list
        System.out.println("list values = " + linkedList);

        LinkedList<String> clonelist = (LinkedList<String>) linkedList.clone();
        //Output the cloned list
        System.out.println("cloned list values = " + clonelist);

        //Equality Check
        System.out.println("Equality Check -> " + (linkedList.get(0) == clonelist.get(0)) + " " + (linkedList.get(0).equals(clonelist.get(0))));
    
					
Output:
list values = [item-0, item-1, item-2]
cloned list values = [item-0, item-1, item-2]
Equality Check -> true true

Tag: Example for clone method of class java.util.LinkedList., LinkedList clone function example , How to use clone method of LinkedList?, Usage of LinkedList.clone, LinkedList.clone() examples

public boolean contains(java.lang.Object arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        //Output the list
        System.out.println("list values = " + linkedList);

        //check the list contains the specified element
        System.out.println("Contains - item-0 ? --> " + linkedList.contains("item-0"));
        System.out.println("Contains - item-999 ? --> " + linkedList.contains("item-999"));
    
					
Output:
list values = [item-0, item-1, item-2]
Contains - item-0 ? --> true
Contains - item-999 ? --> false

Tag: Example for contains method of class java.util.LinkedList., LinkedList contains function example with arguments java.lang.Object arg0, How to use contains method of LinkedList?, Usage of LinkedList.contains, LinkedList.contains() examples

public boolean containsAll(java.util.Collection<?> arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> firstList = new LinkedList();
        firstList.add("item-0");
        firstList.add("item-1");
        firstList.add("item-2");
        //Output the list
        System.out.println("first list values = " + firstList);

        LinkedList<String> secondlist = new LinkedList<>();
        secondlist.add("item-0");
        secondlist.add("item-1");
        //Output the second list
        System.out.println("second list values = " + secondlist);

        System.out.println("Does the firstlist contains all the values of secondlist? --> " + firstList.containsAll(secondlist));
        secondlist.add("item-3");
        //Output the second list
        System.out.println("second list values = " + secondlist);
        System.out.println("Does the firstlist contains all the values of secondlist? --> " + firstList.containsAll(secondlist));
    
					
Output:
first list values = [item-0, item-1, item-2]
second list values = [item-0, item-1]
Does the firstlist contains all the values of secondlist? --> true
second list values = [item-0, item-1, item-3]
Does the firstlist contains all the values of secondlist? --> false

Tag: Example for containsAll method of class java.util.AbstractCollection., AbstractCollection containsAll function example with arguments java.util.Collection<?> arg0, How to use containsAll method of AbstractCollection?, Usage of AbstractCollection.containsAll, AbstractCollection.containsAll() examples

public java.util.Iterator<E> descendingIterator()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        linkedList.add("item-3");
        //Output the list
        System.out.println("list values = " + linkedList);

        //Set the iterator as descending
        Iterator<String> iterator = linkedList.descendingIterator();

        System.out.println("list values in descending order - ");

        while(iterator.hasNext()){
            System.out.println("Values is - " + iterator.next());
        }


    
					
Output:
list values = [item-0, item-1, item-2, item-3]
list values in descending order - 
Values is - item-3
Values is - item-2
Values is - item-1
Values is - item-0

Tag: Example for descendingIterator method of class java.util.LinkedList., LinkedList descendingIterator function example , How to use descendingIterator method of LinkedList?, Usage of LinkedList.descendingIterator, LinkedList.descendingIterator() examples

public E element()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        linkedList.add("item-3");
        //Output the list
        System.out.println("list values = " + linkedList);

        System.out.println("Retrieve the head of the list - " + linkedList.element());
    
					
Output:
list values = [item-0, item-1, item-2, item-3]
Retrieve the head of the list - item-0

Tag: Example for element method of class java.util.LinkedList., LinkedList element function example , How to use element method of LinkedList?, Usage of LinkedList.element, LinkedList.element() examples

public boolean equals(java.lang.Object arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> firstList = new LinkedList<>();
        firstList.add("item-0");
        firstList.add("item-1");
        firstList.add("item-2");
        //Output the first list
        System.out.println("first list values = " + firstList);

        LinkedList<String> secondList = new LinkedList<>();
        secondList.add("item-0");
        secondList.add("item-1");
        secondList.add("item-2");
        //Output the second list
        System.out.println("first list values = " + secondList);

        System.out.println("Are Two list are equals? - " + firstList.equals(secondList));

        //adding few more elemts to the second list
        secondList.add("item-3");
        //Output the second list
        System.out.println("first list values = " + secondList);
        System.out.println("Are Two list are equals? - " + firstList.equals(secondList));

    
					
Output:
first list values = [item-0, item-1, item-2]
first list values = [item-0, item-1, item-2]
Are Two list are equals? - true
first list values = [item-0, item-1, item-2, item-3]
Are Two list are equals? - false

Tag: Example for equals method of class java.util.AbstractList., AbstractList equals function example with arguments java.lang.Object arg0, How to use equals method of AbstractList?, Usage of AbstractList.equals, AbstractList.equals() examples

public void forEach(java.util.function.Consumer<? super T> arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        linkedList.add("item-3");
        //Output the list
        System.out.println("list values = " + linkedList);

        System.out.println("Using foreach list the values - ");
        int i=0;
        for (String str : linkedList) {
            System.out.println("value " + i + " - "+ str);
            i++;
        }
    
					
Output:
list values = [item-0, item-1, item-2, item-3]
Using foreach list the values - 
value 0 - item-0
value 1 - item-1
value 2 - item-2
value 3 - item-3

Tag: Example for forEach method of class java.lang.Iterable., Iterable forEach function example with arguments java.util.function.Consumer<? super T> arg0, How to use forEach method of Iterable?, Usage of Iterable.forEach, Iterable.forEach() examples

public E get(int arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        linkedList.add("item-3");
        //Output the list
        System.out.println("list values = " + linkedList);

        System.out.println("The value at index 2 - " + linkedList.get(2));
    
					
Output:
list values = [item-0, item-1, item-2, item-3]
The value at index 2 - item-2

Tag: Example for get method of class java.util.LinkedList., LinkedList get function example with arguments int arg0, How to use get method of LinkedList?, Usage of LinkedList.get, LinkedList.get() examples

public E getFirst()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        linkedList.add("item-3");
        //Output the list
        System.out.println("list values = " + linkedList);

        System.out.println("The value of first element - " + linkedList.getFirst());
    
					
Output:
list values = [item-0, item-1, item-2, item-3]
The value of first element - item-0

Tag: Example for getFirst method of class java.util.LinkedList., LinkedList getFirst function example , How to use getFirst method of LinkedList?, Usage of LinkedList.getFirst, LinkedList.getFirst() examples

public E getLast()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("item-0");
        linkedList.add("item-1");
        linkedList.add("item-2");
        linkedList.add("item-3");
        //Output the list
        System.out.println("list values = " + linkedList);

        System.out.println("The value of last element - " + linkedList.getLast());
    
					
Output:
list values = [item-0, item-1, item-2, item-3]
The value of last element - item-3

Tag: Example for getLast method of class java.util.LinkedList., LinkedList getLast function example , How to use getLast method of LinkedList?, Usage of LinkedList.getLast, LinkedList.getLast() examples

public int hashCode()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("10");
        linkedList.add("11");
        linkedList.add("12");
        linkedList.add("13");
        //Output the list
        System.out.println("list values = " + linkedList);

        System.out.println("Hashcode of the list - " + linkedList.hashCode());
    
					
Output:
list values = [10, 11, 12, 13]
Hashcode of the list - 49163075

Tag: Example for hashCode method of class java.util.AbstractList., AbstractList hashCode function example , How to use hashCode method of AbstractList?, Usage of AbstractList.hashCode, AbstractList.hashCode() examples

public int indexOf(java.lang.Object arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("Its");
        linkedList.add("all");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values = " + linkedList);

        System.out.println("Index of the element 'Binary' - " + linkedList.indexOf("Binary"));

        //Returns -1 if specified element is not found
        System.out.println("Index of the element 'item' - " + linkedList.indexOf("item"));
    
					
Output:
list values = [Its, all, Binary]
Index of the element 'Binary' - 2
Index of the element 'item' - -1

Tag: Example for indexOf method of class java.util.LinkedList., LinkedList indexOf function example with arguments java.lang.Object arg0, How to use indexOf method of LinkedList?, Usage of LinkedList.indexOf, LinkedList.indexOf() examples

public boolean isEmpty()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        System.out.println("Check list is empty - " + linkedList.isEmpty());

        linkedList.add("Its");
        linkedList.add("all");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values = " + linkedList);

        System.out.println("Check list is empty - " + linkedList.isEmpty());
    
					
Output:
Check list is empty - true
list values = [Its, all, Binary]
Check list is empty - false

Tag: Example for isEmpty method of class java.util.AbstractCollection., AbstractCollection isEmpty function example , How to use isEmpty method of AbstractCollection?, Usage of AbstractCollection.isEmpty, AbstractCollection.isEmpty() examples

public java.util.Iterator<E> iterator()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("Its");
        linkedList.add("all");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values = " + linkedList);

        Iterator<String> iterator = linkedList.iterator();

        while(iterator.hasNext()){
            System.out.println("List value - " + iterator.next());
        }
    
					
Output:
list values = [Its, all, Binary]
List value - Its
List value - all
List value - Binary

Tag: Example for iterator method of class java.util.AbstractSequentialList., AbstractSequentialList iterator function example , How to use iterator method of AbstractSequentialList?, Usage of AbstractSequentialList.iterator, AbstractSequentialList.iterator() examples

public int lastIndexOf(java.lang.Object arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList linkedList = new LinkedList();
        linkedList.add("Hello");
        linkedList.add("Its");
        linkedList.add("all");
        linkedList.add("Binary");
        linkedList.add("Hello");

        //Output the list
        System.out.println("list values = " + linkedList);

        System.out.println("Index of the element 'Binary' - " + linkedList.lastIndexOf("Hello"));

        //Returns -1 if specified element is not found
        System.out.println("Index of the element 'item' - " + linkedList.indexOf("item"));
    
					
Output:
list values = [Hello, Its, all, Binary, Hello]
Index of the element 'Binary' - 4
Index of the element 'item' - -1

Tag: Example for lastIndexOf method of class java.util.LinkedList., LinkedList lastIndexOf function example with arguments java.lang.Object arg0, How to use lastIndexOf method of LinkedList?, Usage of LinkedList.lastIndexOf, LinkedList.lastIndexOf() examples

public java.util.ListIterator<E> listIterator(int arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<Integer> linkedList = new LinkedList<>();
        linkedList.add(10);
        linkedList.add(20);
        linkedList.add(30);
        //Output the list
        System.out.println("list values = " + linkedList);

        Iterator<Integer> iterator = linkedList.listIterator(1);

        while(iterator.hasNext()){
            System.out.println("List value - " + iterator.next());
        }
    
					
Output:
list values = [10, 20, 30]
List value - 20
List value - 30

Tag: Example for listIterator method of class java.util.LinkedList., LinkedList listIterator function example with arguments int arg0, How to use listIterator method of LinkedList?, Usage of LinkedList.listIterator, LinkedList.listIterator() examples

public java.util.ListIterator<E> listIterator()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("Its");
        linkedList.add("All");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values = " + linkedList);

        Iterator<String> iterator = linkedList.listIterator(2);

        while(iterator.hasNext()){
            System.out.println("List value - " + iterator.next());
        }
    
					
Output:
list values = [Its, All, Binary]
List value - Binary

Tag: Example for listIterator method of class java.util.AbstractList., AbstractList listIterator function example , How to use listIterator method of AbstractList?, Usage of AbstractList.listIterator, AbstractList.listIterator() examples

public boolean offer(E arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("Its");
        linkedList.add("All");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values before offer() - " + linkedList);

        //Add the element as tail
        linkedList.offer("Welcomes You!!");

        System.out.println("list values after offer() - " + linkedList);
    
					
Output:
list values before offer() - [Its, All, Binary]
list values after offer() - [Its, All, Binary, Welcomes You!!]

Tag: Example for offer method of class java.util.LinkedList., LinkedList offer function example with arguments E arg0, How to use offer method of LinkedList?, Usage of LinkedList.offer, LinkedList.offer() examples

public boolean offerFirst(E arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("Its");
        linkedList.add("All");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values before offerFirst() - " + linkedList);

        //Inserts the specified element at the front of this list.
        linkedList.offerFirst("Welcome!!");

        System.out.println("list values after offerFirst() - " + linkedList);
    
					
Output:
list values before offerFirst() - [Its, All, Binary]
list values after offerFirst() - [Welcome!!, Its, All, Binary]

Tag: Example for offerFirst method of class java.util.LinkedList., LinkedList offerFirst function example with arguments E arg0, How to use offerFirst method of LinkedList?, Usage of LinkedList.offerFirst, LinkedList.offerFirst() examples

public boolean offerLast(E arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("Its");
        linkedList.add("All");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values before offerLast() - " + linkedList);

        //Inserts the specified element at the end of this list.
        linkedList.offerLast("Welcomes You!!");

        System.out.println("list values after offerLast() - " + linkedList);
    
					
Output:
list values before offerLast() - [Its, All, Binary]
list values after offerLast() - [Its, All, Binary, Welcomes You!!]

Tag: Example for offerLast method of class java.util.LinkedList., LinkedList offerLast function example with arguments E arg0, How to use offerLast method of LinkedList?, Usage of LinkedList.offerLast, LinkedList.offerLast() examples

public E peek()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("Its");
        linkedList.add("All");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Retrieves, but does not remove, the head (first element) of this list.
        System.out.println("The head of this list is - " + linkedList.peek());

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
list values - [Its, All, Binary]
The head of this list is - Its
list values - [Its, All, Binary]

Tag: Example for peek method of class java.util.LinkedList., LinkedList peek function example , How to use peek method of LinkedList?, Usage of LinkedList.peek, LinkedList.peek() examples

public E peekFirst()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();

        System.out.println("The head of this list is - " + linkedList.peekFirst());

        linkedList.add("Its");
        linkedList.add("All");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Retrieves, but does not remove, the first element of this list, or returns null if this list is empty.
        System.out.println("The head of this list is - " + linkedList.peekFirst());

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
The head of this list is - null
list values - [Its, All, Binary]
The head of this list is - Its
list values - [Its, All, Binary]

Tag: Example for peekFirst method of class java.util.LinkedList., LinkedList peekFirst function example , How to use peekFirst method of LinkedList?, Usage of LinkedList.peekFirst, LinkedList.peekFirst() examples

public E peekLast()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();

        System.out.println("The head of this list is - " + linkedList.peekLast());

        linkedList.add("Its");
        linkedList.add("All");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Retrieves, but does not remove, the last element of this list, or returns null if this list is empty.
        System.out.println("The last element of this list is - " + linkedList.peekLast());

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
The head of this list is - null
list values - [Its, All, Binary]
The last element of this list is - Binary
list values - [Its, All, Binary]

Tag: Example for peekLast method of class java.util.LinkedList., LinkedList peekLast function example , How to use peekLast method of LinkedList?, Usage of LinkedList.peekLast, LinkedList.peekLast() examples

public E poll()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("Its");
        linkedList.add("All");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Retrieves and removes the head (first element) of this list.
        System.out.println("The head of this list is - " + linkedList.poll());

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
list values - [Its, All, Binary]
The head of this list is - Its
list values - [All, Binary]

Tag: Example for poll method of class java.util.LinkedList., LinkedList poll function example , How to use poll method of LinkedList?, Usage of LinkedList.poll, LinkedList.poll() examples

public E pollFirst()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();

        System.out.println("The head of this list is - " + linkedList.pollFirst());

        linkedList.add("Its");
        linkedList.add("All");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Retrieves and removes the first element of this list, or returns null if this list is empty.
        System.out.println("The head of this list is - " + linkedList.pollFirst());

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
The head of this list is - null
list values - [Its, All, Binary]
The head of this list is - Its
list values - [All, Binary]

Tag: Example for pollFirst method of class java.util.LinkedList., LinkedList pollFirst function example , How to use pollFirst method of LinkedList?, Usage of LinkedList.pollFirst, LinkedList.pollFirst() examples

public E pollLast()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();

        System.out.println("The last element of this list is - " + linkedList.pollLast());

        linkedList.add("Its");
        linkedList.add("All");
        linkedList.add("Binary");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Retrieves and removes the last element of this list, or returns null if this list is empty.
        System.out.println("The last element of this list is - " + linkedList.pollLast());

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
The last element of this list is - null
list values - [Its, All, Binary]
The last element of this list is - Binary
list values - [Its, All]

Tag: Example for pollLast method of class java.util.LinkedList., LinkedList pollLast function example , How to use pollLast method of LinkedList?, Usage of LinkedList.pollLast, LinkedList.pollLast() examples

public E pop()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.push("Apple");
        linkedList.push("Banana");
        linkedList.push("Orange");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Pops an element from the stack represented by this list.
        System.out.println("Pop the first element - " + linkedList.pop());
        System.out.println("Pop the second element - " + linkedList.pop());

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
list values - [Orange, Banana, Apple]
Pop the first element - Orange
Pop the second element - Banana
list values - [Apple]

Tag: Example for pop method of class java.util.LinkedList., LinkedList pop function example , How to use pop method of LinkedList?, Usage of LinkedList.pop, LinkedList.pop() examples

public void push(E arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();

        //Pushes an element onto the stack represented by this list.
        linkedList.push("Apple");
        linkedList.push("Banana");
        linkedList.push("Orange");
        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
list values - [Orange, Banana, Apple]

Tag: Example for push method of class java.util.LinkedList., LinkedList push function example with arguments E arg0, How to use push method of LinkedList?, Usage of LinkedList.push, LinkedList.push() examples

public boolean remove(java.lang.Object arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList linkedList = new LinkedList();
        linkedList.push("Apple");
        linkedList.push("Banana");
        linkedList.push("Orange");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Retrieves and removes the head (first element) of this list.
        linkedList.remove();

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
list values - [Orange, Banana, Apple]
list values - [Banana, Apple]

Tag: Example for remove method of class java.util.LinkedList., LinkedList remove function example with arguments java.lang.Object arg0, How to use remove method of LinkedList?, Usage of LinkedList.remove, LinkedList.remove() examples

public E remove(int arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.push("Its");
        linkedList.push("All");
        linkedList.push("Binary");
        linkedList.push("Guys");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Removes the element at the specified position in this list.
        linkedList.remove(3);

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
list values - [Guys, Binary, All, Its]
list values - [Guys, Binary, All]

Tag: Example for remove method of class java.util.LinkedList., LinkedList remove function example with arguments int arg0, How to use remove method of LinkedList?, Usage of LinkedList.remove, LinkedList.remove() examples

public E removeFirst()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.push("Its");
        linkedList.push("All");
        linkedList.push("Binary");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Removes and returns the first element from this list.
        linkedList.removeFirst();

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
list values - [Binary, All, Its]
list values - [All, Its]

Tag: Example for removeFirst method of class java.util.LinkedList., LinkedList removeFirst function example , How to use removeFirst method of LinkedList?, Usage of LinkedList.removeFirst, LinkedList.removeFirst() examples

public boolean removeFirstOccurrence(java.lang.Object arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList linkedList = new LinkedList();
        linkedList.add("Car");
        linkedList.add("Motor-Bike");
        linkedList.add("Bicycle");
        linkedList.add("Bus");
        linkedList.add("Car");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Removes the first occurrence of the specified element in this list (when traversing the list from head to tail).
        linkedList.removeFirstOccurrence("Car");

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
list values - [Car, Motor-Bike, Bicycle, Bus, Car]
list values - [Motor-Bike, Bicycle, Bus, Car]

Tag: Example for removeFirstOccurrence method of class java.util.LinkedList., LinkedList removeFirstOccurrence function example with arguments java.lang.Object arg0, How to use removeFirstOccurrence method of LinkedList?, Usage of LinkedList.removeFirstOccurrence, LinkedList.removeFirstOccurrence() examples

public E removeLast()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.push("Its");
        linkedList.push("All");
        linkedList.push("Binary");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Removes and returns the last element from this list.
        linkedList.removeLast();

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
list values - [Binary, All, Its]
list values - [Binary, All]

Tag: Example for removeLast method of class java.util.LinkedList., LinkedList removeLast function example , How to use removeLast method of LinkedList?, Usage of LinkedList.removeLast, LinkedList.removeLast() examples

public boolean removeLastOccurrence(java.lang.Object arg0)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("Car");
        linkedList.add("Motor-Bike");
        linkedList.add("Bicycle");
        linkedList.add("Bus");
        linkedList.add("Car");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Removes and returns the last element from this list.
        linkedList.removeLastOccurrence("Car");

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
list values - [Car, Motor-Bike, Bicycle, Bus, Car]
list values - [Car, Motor-Bike, Bicycle, Bus]

Tag: Example for removeLastOccurrence method of class java.util.LinkedList., LinkedList removeLastOccurrence function example with arguments java.lang.Object arg0, How to use removeLastOccurrence method of LinkedList?, Usage of LinkedList.removeLastOccurrence, LinkedList.removeLastOccurrence() examples

public E set(int arg0, E arg1)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("Car");
        linkedList.add("Bus");
        linkedList.add("Motor-Bike");
        linkedList.add("Bicycle");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Replace any particular element in the linked list
        linkedList.set(2, "Boat");

        //Output the list
        System.out.println("list values - " + linkedList);
    
					
Output:
list values - [Car, Bus, Motor-Bike, Bicycle]
list values - [Car, Bus, Boat, Bicycle]

Tag: Example for set method of class java.util.LinkedList., LinkedList set function example with arguments int arg0, E arg1, How to use set method of LinkedList?, Usage of LinkedList.set, LinkedList.set() examples

public int size()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("Car");
        linkedList.add("Bus");
        linkedList.add("Motor-Bike");
        linkedList.add("Bicycle");
        //Output the list
        System.out.println("list values - " + linkedList);

        //Returns the number of elements in this list.
        System.out.println("Total size - " + linkedList.size());
    
					
Output:
list values - [Car, Bus, Motor-Bike, Bicycle]
Total size - 4

Tag: Example for size method of class java.util.LinkedList., LinkedList size function example , How to use size method of LinkedList?, Usage of LinkedList.size, LinkedList.size() examples

Imports

[↑ Method List]

Import statements used in examples.

				java.util.Iterator
java.util.LinkedList
java.util.Collection
java.util.function.Consumer
java.util.function.Predicate
java.util.function.UnaryOperator
java.util.Comparator
java.util.function.IntFunction
		

Tag: Simple working examples of methods / functions of class java.util.LinkedList along with their console output, java.util.LinkedList tutorial., Guide to java.util.LinkedList & its methods., Understanding java.util.LinkedList with examples.