Stacks stack of Java collection classes

Source: Internet
Author: User

 Packagecom.test;ImportJava.util.*; Public classDemo7_3 { Public Static voidMain (string[] args) {//TODO auto-generated Method StubEMP EMP=NewEMP ("sa001", "Xiaoming", 12.3f); Stack Stack=NewStack ();        Stack.add (EMP);  for(inti = 0; I < stack.size (); i++) {EMP temp=(EMP) stack.get (i);                    System.out.println (Temp.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; }}

Stacks stack of Java collection classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.