8:24 pm - Thursday April 25, 2019

LinkedList Example Program for offerFirst(E e)

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
//LinkedList Example Program for offerFirst(E e)
/**
Author :candidjava.com
Description: Inserts the specified element at the front of this list..
 */
import java.io.IOException;
import java.util.*;

public class DeeLinkedListOfferFirst {
	public static void main(String args[]) {
		boolean a;
		int b = 60, c = 20, d = 30, f = 80, e = 0;
		LinkedList l = new LinkedList();
		ListIterator t;
		a = l.add(b);
		a = l.add(c);
		a = l.add(d);
		t = l.listIterator(e);
		while (t.hasNext()) {
			System.out.println(t.next());
		}
		a = l.offerFirst(f);// Inserts element 80 at the front of this list.
		System.out.println(f + "is added at first position ");
		System.out.println(" ");
		t = l.listIterator(e);
		while (t.hasNext()) {
			System.out.println(t.next());
		}
	}
}

Output
elements in the list are
60
20
30
80 is added as a first element in the list
80
60
20
30

Filed in: Z-A All Java Codes

Comments are closed.