9:32 pm - Saturday January 21, 2017

LinkedList to add element on output Offer() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This Program is used to add element using Offer() method.

Example Program


package com.example;

package com.example;

import java.util.*;

public class LinkedListOffer {
	public static void main(String[] args) { // create a LinkedList
		LinkedList list = new LinkedList(); // add some elements
		list.add("Welcome");
		list.add("to");
		list.add("Java Class");
		list.add("at 10am"); // print the list
		System.out.println("LinkedList:" + list); // offer a new element
		list.offer("in chennai");// print the new list
		System.out.println("LinkedList:" + list);
	}
}

 

output:

LinkedList[Welcome, to, Java Class, at 10am]

LinkedList[Welcome, to, Java Class, at 10am , in chennai]

 

Description

The java.util.LinkedList.offer(E e) method adds the specified element as the tail (last element) of this list.

Declaration

Following is the declaration for java.util.LinkedList.offer() method

public boolean offer(E e)

Parameters

  • e — the element to add

Return Value

This method returns true

Exception

  • NA

BACK

Filed in: Java Examples

Comments are closed.