LinkedList boolean add(E e) method Example Program


Appends the specified element to the end of this list.

Program

package com.candidjava;

import java.util.LinkedList;

/**
 * 
 * @author : mohan
 * @Description : The java.util.LinkedList.add(E e) method appends the specified
 *              element to the end of this list.
 *
 */
public class LinkedListAdd {

	public static void main(String[] args) {

		LinkedList list = new LinkedList();
		list.add("karthi");
		list.add("mohan");
		list.add("anand");
		list.add("hari");
		System.out.println("LinkedList:" + list);
		list.add("vinoth");
		System.out.println("LinkedList:" + list);
	}
}

Output

LinkedList:[karthi, mohan, anand, hari]
LinkedList:[karthi, mohan, anand, hari, vinoth]

Explanation

public boolean add(E e)
Appends the specified element to the end of this list.
This method is equivalent to addLast(E).
Specified by:
add in interface Collection
Specified by:
add in interface Deque
Specified by:
add in interface List
Specified by:
add in interface Queue
Overrides:
add in class AbstractList
Parameters:
e - element to be appended to this list
Returns:
true (as specified by Collection.add(E))


Related Post

Comments


©candidjava.com