哈希表打印和添加显示内存位置的值

时间:2014-07-01 13:53:50

标签: java hash printing hashtable

我正在尝试为我的Car类(一个添加函数和一个打印函数)编写一个哈希表函数,但它一直显示内存位置...编写一个名为public void printCustomerWaitingOnCar()的函数,它打印出哈希表(基本上是每个客户的名字 - >制作他正在等待的汽车模型)。编写一个名为public boolean addCustomerWaitOnCar(Customer aCustomer,Car aCar)的函数,它为aCustomer(等待)aCar添加一个新的键值对。确保键值对不存在,这意味着不应将与aCustomer同名的客户映射到与aCar具有相同品牌/型号的Car。

private Hashtable<Customer, Car> CustomerWaitingOnCar = new Hashtable<Customer, Car>();


    public void printCustomerWaitingOnCar() {
        Enumeration<Customer> items = CustomerWaitingOnCar.keys();

        System.out.println("-------------------------");

        while (items.hasMoreElements()) {
            System.out.println("INSIDE WHILE LOOP");

            //Customer cusKey = (Customer)items.nextElement();
            //CustomerWaitingOnCar.put(cusKey, Car);
            System.out.println("Customer: " + items.nextElement());

        }
        System.out.println("OUTSIDE WHILE LOOP");

    }




    public boolean addCustomerWaitOnCar(Customer aCustomer, Car aCar){

        CustomerWaitingOnCar.put(aCustomer, aCar);

        System.out.println("Customer: " + aCustomer + " Car: " + aCar);

        return true;


    }

上述两个功能。
       输出(当前显示的内容)

   Customer: Practice.Customer@5bdf59bd Car: Practice.Car@247cb66a// memory location
   Customer: Practice.Customer@77abfbdc Car: Practice.Car@3c2465e5// memory location
   Customer: Practice.Customer@799dbc3b Car: Practice.Car@62b103dd// memory location
   -------------------------
   INSIDE WHILE LOOP
   Customer: Practice.Customer@77abfbdc // memory location
   INSIDE WHILE LOOP
   Customer: Practice.Customer@5bdf59bd// memory location
   INSIDE WHILE LOOP
   Customer: Practice.Customer@799dbc3b// memory location
   OUTSIDE WHILE LOOP

0 个答案:

没有答案