Thursday, 12 April 2018

Corejava-Slip29


Slip29. Write a java program to accept n employee names from user, store them into the
LinkedList class and display them by using.
a. Iterator Interface
b. ListIterator Interface

import java.util.*;
import java.io.*;
public class Slip29
{
public static void main(String args[])throws Exception
{
int n;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
LinkedList li = new LinkedList ();
System.out.println("\nEnter number of Employee : ");
n = Integer.parseInt(br.readLine());
System.out.println("\nEnter name : ");
for(int i = 1; i <= n; i++)
{
li.add(br.readLine());
}
System.out.println("\nLink List Content : ");
Iterator it = li.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
System.out.println("\nReverse order : ");
ListIterator lt = li.listIterator();
while(lt.hasNext())
{
lt.next();
}
while(lt.hasPrevious())
{
System.out.println(lt.previous());
}
}
}