3:06 pm - Tuesday September 26, 3026

LinkedList Example Program for peek()

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
/**
 *@Author:candid
 *@Definition:find head of the list using peek()
 *@class:Peek
 */
import java.util.*;

public class Peek {
	public static void main(String args[]) {
		LinkedList<String> ls = new LinkedList<String>();// create ls object for
															// LinkedList
		ls.add("welcome");// add content to the ls
		ls.add("to");// add content to the ls
		ls.add("chennai");// add content to the ls
		System.out.println("linkedlist:" + ls);
		System.out.println("head of the list:" + ls.peek());// print head of the
															// list
	}
}

Output:

linkedlist:[welcome,to,chennai]
head of the list:welcome

BACK

 
Filed in: Z-A All Java Codes

Comments are closed.