我刚刚了解了HashMap。我试图从HashMap打印对象值,但不知何故,我只是垃圾而且没有错误。
请帮忙。
public static void main(String[] args) {
Products product1 = new Products("Electric Drill", "$30", "3");
HashMap <Integer, Products> productsHM = new HashMap<Integer, Products>();
productsHM.put(10, product1);
Shop obj = new Shop();
Set s = productsHM.entrySet();
Iterator itr = s.iterator();
while (itr.hasNext())
{
Map.Entry mapEntry = (Map.Entry) itr.next();
System.out.println("Product ID: " + mapEntry.getKey() + " | Product: " + mapEntry.getValue());
}
}