Related Examples
 

Java LinkedList peek Example

LinkedList class peek method example. This example shows you how to use peek method.


LinkedList class peek method example.public LinkedList peek() Retrieves, but does not remove, the head (first element) of this list.

Here is the code

/**
 * @ # Peek.java
 * A class repersenting use to peek method of LinkedList class in java.util package
 * version 15 May 2008
 * author Rose India 
 */
import java.util.*;

public class Peek {

    public static void main(String args[]) {
        LinkedList list = new LinkedList();
        int i = 11;
        String str = "Rose";

        //Add the specified element to the end of this list.
        list.add(i);
        list.add(str);

        //peek of the list
        System.out.println("Peek element = " + list.peek());
    }
}

Output
Peek element = 11

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US