[Java] package test; import java. io. bufferedReader; import java. io. inputStreamReader; import java. util. *;/** Author: Zhong Zhigang * function: Set frame * Time: 2013-1-26*1, List structure: ArrayList, sorted List, Vector, Stack; * 2, Map Structure: HashMap, hashtable; (map, ing) * 3, set structure: HastSet, TreeSet; * 4, Queue structure: Queue interface * 5, difference between Hashtable and HashMap * historic: hashtable appeared earlier. Based on the obsolete Dictionary, HashMap is an interface Map implementation of Java * synchronization: Hashtable is synchronous, thread-safe, and HashMap is different. Step by step, efficient * NULL: HashMap allows null values (Key or vaule), Hashtable cannot * 6, the difference between ArrayList and Vector * synchronization: the Vector is synchronized, thread-safe, asynchronous and efficient * Data growth in ArrayList: by default, Vector doubles, and ArrayList doubles. When storing a large amount of data, Vector, * 7, summary of collection usage: * thread security is required. Using Vector, Hasstable * does not require thread security or concurrency. Using ArrayList, sorted list, And HashMap * requires key-value pairs, the use of HashMap and Hashtable * requires a large amount of data and thread security, use the Vector */public class Collection framework {/*** @ param args */public static void main (String [] args) throws Ex Ception {// ArrayList <Clerk> al = new ArrayList <Clerk> (); Clerk c1 = new Clerk ("", 50,100 0); al. add (c1); // add to the end Clerk c3 = new Clerk ("Wu Yong", 45,200 0); al. add (c3); // add it to the end of al. add (c3); // you can add the same object System. out. println ("al. lenght = "+ al. size (); Clerk c2 = new Clerk ("Wu Song", 30,100 04.4f); al. add (0, c2); // add it to the specified location. The original location will be shown as "al. remove (3); // Delete the corresponding object // System. out. println (al. get (1 ). getName (); for (Clerc: Al) {// System. out. println (c. getName ();} // Lists List. sequential list ll = new sequential list (); ll. addFirst (c1); // Add to the top of the list, which is equivalent to the al. add (0, c2); ll. addLast (c2); // Add it to the last ll. addLast (c2); System. out. println ("listing list. getFirst () --- "+ (Clerk) ll. getFirst ()). getName (); System. out. println ("listing list. getList () --- "+ (Clerk) ll. getLast ()). getName (); for (int I = 0; I <ll. size (); I ++) {System. out. Println ("logical lsit-for-" + (Clerk) ll. get (I )). getName ();} // ll. removeFirst (); // ll. removeLast (); ll. removeFirstOccurrence (c2); // Delete the first element that is the same as C2 from the beginning ll. removeLastOccurrence (c2); // Delete the first element from the end of the for (int I = 0; I <ll. size (); I ++) {System. out. println ("logical lsit-for-" + (Clerk) ll. get (I )). getName ();} // Vector, Vector vv = new Vector (); vv. add (c1); vv. add (c2); for (int I = 0; I <vv. size (); I + +) {System. out. println ("vector-for-" + (Clerk) vv. get (I )). getName ();} // Stack, Stack ss = new Stack (); ss. add (c1); // It is added to the front by default, which is the pressure stack ??? This does not appear to be the case after testing. add (c2); for (int I = 0; I <ss. size (); I ++) {System. out. println ("Stack-for-" + (Clerk) ss. get (I )). getName ();} System. out. println ("stack =" + (Clerk) ss. get (0 )). getName (); // HashMap, HashMap hm = new HashMap (); hm. put ("", c1); hm. put ("Wu Song", c2); hm. put ("", c3); // when the Key is the same, it can be superimposed, but it cannot be repeated. It can only be replaced. Song Jiang will become Wu Yong // search for Song Jiang's information if (hm. containsKey ("") {System. out. println ("HashMap ---" + ""); Clerk mc = (Clerk) hm. get ("");} else {System. out. println ("HashMap ---" + "");} // traverse the HashMap and use the iterator Iterator iterator it = hm. keySet (). iterator (); while (it. hasNext () {// whether there is another // retrieve Key String key = it. next (). toString (); Clerk c = (Clerk) hm. get (key); System. out. println ("HashMap =" + c. getName ();} // Hashta Ble, which is similar to HashMap in usage. // a class is used to manage employee information. EmpManage emp = new EmpManage (); // read the input BufferedReader br = new BufferedReader (new InputStreamReader (System. in); while (true) {System. out. println ("follow the prompts"); System. out. println ("1: add an employee"); System. out. println ("2: Find an employee"); System. out. println ("3: modifying an employee's salary"); System. out. println ("4: deleting an employee"); System. out. println ("6: Find all employees"); System. out. println ("5: Exit program"); String op = br. ReadLine (); if (op. equals ("1") {System. out. println ("Enter the name:"); String name = br. readLine (); System. out. println ("Enter age:"); int age = Integer. valueOf (br. readLine (); System. out. println ("Enter the salary:"); float sal = Float. parseFloat (br. readLine (); Clerk c = new Clerk (name, age, sal); emp. addEmp (c); // System. out. println ("successfully added");} else if (op. equals ("2") {System. out. println ("Enter employee name"); String qname = br. read Line (); emp.info (qname);} else if (op. equals ("3") {System. out. println ("enter the name of the employee to be modified:"); String uname = br. readLine (); System. out. println ("Enter the salary to be modified:"); float newsal = Float. parseFloat (br. readLine (); emp. updateSal (uname, newsal); // System. out. println ("modified successfully");} else if (op. equals ("4") {System. out. println ("enter the name of the employee to be deleted:"); String dname = br. readLine (); emp. delEmp (dname); // System. out. println ("deleted successfully ");} Else if (op. equals ("5") {System. exit (0);} else if (op. equals ("6") {emp. queal () ;}}} class EmpManage {// employee management class private ArrayList <Clerk> al = null; public EmpManage () {al = new ArrayList <Clerk> ();} public void queal () {for (Clerc: al) {System. out. println ("employee name:" + c. getName () + ", salary:" + c. getSal () + ", age:" + c. getAge () ;}}// add employee public void addEmp (Clerc) {al. add (c);} // Delete employee public void d ElEmp (String name) {boolean B = false; for (Clerc: al) {if (c. getName (). equals (name) {// String type data is compared with the address al with =. remove (c); B = true; break;} if (! B) {System. out. println ("");} else {System. out. println ("deleted successfully") ;}// display employee information public void info (String name) {boolean B = false; for (int I = 0; I <al. size (); I ++) {Clerc = al. get (I); if (c. getName (). equals (name) {B = true; System. out. println ("your employee:" + c. getName () + ", salary:" + c. getSal () + ", age:" + c. getAge (); break ;}} if (! B) {System. out. println ("");} else {System. out. println ("query succeeded") ;}// modify employee salary public void updateSal (String name, float sal) {boolean B = false; for (Clerc: al) {if (c. getName (). equals (name) {c. setSal (sal); B = true ;}} if (! B) {System. out. println ("");} else {System. out. println ("modified successfully") ;}} class Clerk {// employee class private String name; public String getName () {return name;} public void setName (String name) {this. name = name;} public int getAge () {return age;} public void setAge (int age) {this. age = age;} www.2cto.com public float getSal () {return sal;} public void setSal (float sal) {this. sal = sal;} private int age; private float sal; public Clerk (String name, int age, float sal) {this. age = age; this. name = name; this. sal = sal ;}}