Java LinkedList - offer() Method
The java.util.LinkedList.offer() method is used to add the specified element at the end of the list.
Syntax
public boolean offer(E element)
Here, E is the type of element maintained by the container.
Parameters
element |
Specify element which need to be added in the list. |
Return Value
true.
Exception
NA
Example:
In the example below, the java.util.LinkedList.offer() method is used to add the specified element at the end of the given list.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a linkedlist LinkedList<Integer> MyList = new LinkedList<Integer>(); //populating linkedlist using offer method MyList.offer(10); MyList.offer(20); MyList.offer(30); //printing linkedlist System.out.println("MyList contains: " + MyList); } }
The output of the above code will be:
MyList contains: [10, 20, 30]
❮ Java.util - LinkedList