Packagecom.test;ImportJava.util.*; Public classDemo7_3 { Public Static voidMain (string[] args) {//TODO auto-generated Method StubLinkedList ll=NewLinkedList (); EMP EMP1=NewEMP ("Sa01", "AA", 1.2f); EMP EMP2=NewEMP ("sa02", "BB", 1.2f); //indicates that the EMP is loaded at the front of the listLl.addfirst (EMP1); Ll.addfirst (EMP2); Ll.addlast (EMP1); Ll.addlast (EMP2); for(inti = 0; I < ll.size (); i++) {System.out.println ((EMP) ll.get (i)). GetName ()); } //ll.remove (0);// //for (int i = 0; i < ll.size (); i++) {//System.out.println ((EMP) ll.get (i)). GetName ());// } }}//Employee Management ClassclassEmpmanage {PrivateArrayList Al =NULL; //The main function of constructors is to initialize member variables PublicEmpmanage () {Al=NewArrayList (); } //Join the Staff Public voidaddemp (emp emp) {al.add (EMP); } //display information about the employee according to the employee number Public voidshowinfo (String empNo) {//traverse the entire ArrayList for(inti = 0; I < al.size (); i++) { //Remove EMP ObjectEMP emp =(EMP) al.get (i); //Compare Numbers if(Emp.getempno (). Equals (EmpNo)) {System.out.println ("Find the employee, his message is"); System.out.println ("Number =" +empNo); System.out.println ("First name =" +emp.getname ()); System.out.println ("Wage =" +emp.getsal ()); } } } //Revise salary Public voidUpdatesal (String EmpNo,floatnewsal) { for(inti = 0; I < al.size (); i++) {EMP emp=(EMP) al.get (i); if(Emp.getempno (). Equals (EmpNo)) {//Revise salaryemp.setsal (newsal); } } } //Delete Employee Public voiddelemp (String empNo) { for(inti = 0; I < al.size (); i++) {EMP emp=(EMP) al.get (i); if(Emp.getempno (). Equals (EmpNo)) {//two ways to deleteAl.remove (i); //al.remove (EMP); } } }}//Employee ClassclassEMP {//School Number PrivateString EmpNo; PrivateString name; Private floatSal; //constructor Function PublicEMP (String empNo, string name,floatSal) { Super(); This. EmpNo =EmpNo; This. Name =name; This. Sal =Sal; } PublicString Getempno () {returnEmpNo; } Public voidsetempno (String empNo) { This. EmpNo =EmpNo; } PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; } Public floatgetsal () {returnSal; } Public voidSetsal (floatSal) { This. Sal =Sal; }}
LinkedList List of Java collection classes