Java 8Object Oriented ProgrammingProgramming

A single element can be added to a LinkedList by using the java.util.LinkedList.add() method. This method has one parameter parameters i.e. the element that is to be inserted in the LinkedList.

A program that demonstrates this is given as follows −

## Example

Live Demo

import java.util.LinkedList;
public class Demo {
public static void main(String[] args) {
System.out.println("The LinkedList is: " + l);
}
}

## Output

The LinkedList is: [Magic]

Now let us understand the above program.

LinkedList<String> l = new LinkedList<String>();
System.out.println("The LinkedList is: " + l);