Question: PLEASE ANS IN JAVA How would I access an attribute of a specific object if the object is key in a Hashmap? In the example
PLEASE ANS IN JAVA
How would I access an attribute of a specific object if the object is key in a Hashmap? In the example below I want to access the Id attribute which is in my object Product from my hashmap key. Please let me know if I don't make sense and I can rephrase my question.
public class Product { private String name; private int Id; private double price; public Product(String Name, int Id, double Price) { this.name = Name; this.Id = ID; this.price = Price; } A //Getter Methods public String getName() {return name;} public int getId() {return Id;} public double getPrice() {return price;} } public class Inventory2 { //Var Declarations private int quantity; private Product type; private Map
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts


