Java Foundation Article-hashmap

Source: Internet
Author: User

/class depositor

Package bank depositors; public class Depositor {private string Id;private string Name;private double balance;public depositor (string Id,string name,double Bal) {//TODO auto-generated constructor Stubsuper (); this.id=id;this.name=name;this.balance = Bal ;} Public double GetBalance () {return balance;} public void setbalance (double balance) {this.balance = balance;} Public String GetId () {return ID;} public void SetId (String id) {this.id = ID;} Public String GetName () {return name;} public void SetName (String name) {this.name=name;}    }

/class TestMap

Package bank depositors; import Java.util.hashmap;import java.util.iterator;import java.util.map;import java.util.set;public Class TestMap {public double getbalance (Map depositor,string id) {System.out.print ("ID:" +id); return Depositor.get (ID). Hashcode ();} public static void Main (String args[]) {Map h = new HashMap (); Depositor a1 = new depositor ("1001", "Zhangsan", 12345); depositor A2 = new Depositor ("1002", "Tom", 8888.50);D epositor a3 = new Depositor ("1003", "Mary", 6666); H.put ("1001", A1); H.put ("1002", a2); H.put ("1003", A3); TestMap Hme = new TestMap ();//mapset keyset= H.keyset (); Iterator it = Keyset.iterator ();d ouble sum = 0;while (It.hasnext ()) {Object key = It.next ();D epositor a = (depositor) h.get (key); SYSTEM.OUT.PRINTLN ("ID:" +a.getid () + "Balance?" +a.getbalance ()); Sum + = A.getbalance ();} System.out.println ("sum:?") +sum);}}

  

Java Foundation Article-hashmap

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.