Collection of Framework
Collection of Framework
1)
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
ListIterator Interface
package javacollection;
import java.util.*;
int n;
int i;
LinkedList list=new LinkedList();
Scanner sc=new Scanner(System.in);
System.out.println("Enter the element Size :-");
n=sc.nextInt();
System.out.println("Enter employees name :-");
for( i=1;i<=n;i++)
{
String p=sc.next();
list.add(p);
}
Iterator<?> itr=list.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.*;
String t = sc.next();
student.add(t);
ArrayList s= student;
System.out.println("student name"+s);
Collections.sort(student);
}
}
3) Write a java program to accept the details of ‘n’ employees (EName ,Salary)
from the user, store them into the Hashtable and displays the Employee Names
having maximum Salary.
package arraylist;
import java.util.*;
employeeTable.put(eName, salary);
}
4)
import java.io.*;
import java.util.*;
public class collseta1 {
5)
import java.io.*;
import java.util.*;
public class collseta2 {
int ch;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
LinkedList l=new LinkedList();
l.add("red");
l.add("blue");
l.add("yellow");
l.add("orange");
Iterator itr=l.iterator();
ListIterator litr=l.listIterator();
do
{
System.out.println("\n1:Display List");
System.out.println("2:Display List In Reveres Order");
System.out.println("3:Create New List");
System.out.println("4:Exit");
System.out.println("Enter your choice :");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.println("Content of list:");
while(itr.hasNext())
{
String e=(String)itr.next();
System.out.println(e);
}
break;
case 2:
System.out.println("Content of list:");
System.out.println(l);
System.out.println("Content of list in reverse
order :");
while(litr.hasNext())
{
String e=(String)litr.next();
}
while(litr.hasPrevious())
{
//String e=(String)itr.next();
System.out.println(litr.previous());
}
break;
case 3:
System.out.println("\nudating link list item :");
l.set(0,"red");
l.set(1,"blue");
l.set(2,"pink");
l.set(3,"green");
l.add("yellow");
l.add("orange");
System.out.println(l);
break;
}
}while(ch!=4);
}
6) import java.io.*;
import java.util.*;
public class collseta3 {
7)
import java.io.*;
import java.util.*;
import java.util.Collections;
public class collseta11 {
}
}
8) import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class collsetb1 extends JFrame implements ActionListener
{
java.awt.List l1;
JTextField t1,t2,t3,t4;
JButton b1,b2,b3;
Hashtable HT;
collsetb1()
{
super("collsetb1");
setSize(600,400);
setLayout(null);
setLocation(200,200);
l1=new java.awt.List(15);
t1=new JTextField();
t2=new JTextField();
t3=new JTextField();
t4=new JTextField();
b1=new JButton("Add");
b2=new JButton("Remove");
b3=new JButton("Search");
l1.setBounds(100,100,150,110);
t1.setBounds(260,100,100,20);
t2.setBounds(370,100,100,20);
b1.setBounds(260,130,210,20);
t3.setBounds(260,160,100,20);
t4.setBounds(370,160,100,20);
b2.setBounds(260,190,100,20);
b3.setBounds(370,190,100,20);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
HT=new Hashtable();
t1.requestFocus();
HT.put(t1.getText(), new
Integer(Integer.parseInt(t2.getText())));
t1.setText("");
t2.setText("");
t1.requestFocus();
JOptionPane.showMessageDialog(null,HT);
}
if(e.getSource()==b2)
{
if(t3.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"Enter city
name to remove");
t3.requestFocus();
}
else
{
if(HT.containsKey(t3.getText()))
HT.remove(t3.getText());
JOptionPane.showMessageDialog(null,HT);
}
if(e.getSource()==b3)
{
if(t4.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"Enter city
name to search");
t4.requestFocus();
}
else
{
JOptionPane.showMessageDialog(null,"Value
="+HT.get(t4.getText()));
}
}
}