im new java please forgive ignorance,i trying best not ask stupid question.
i need write method takes 2 arguments, 1 being key map (string) other value (my map has values sets of user defined object called object has 3 string values itself).
so far have:
public void addmapobject(string akey, object anobject)//what anobject arguement like?
{ set objects = new hashset<>(); objects.add(new object("","",""); //how initialize these values? mymap.put(akey, objects); }
apologies if not clear happy clarify if needed.
thank has clicked now.
you first have create object, so:
pubic class myobject{ private string something; private integer something2; private double something3; //or whatever data types want //generate getters , setters }
so have object holds something.
after that, have initialize map hold object in method above or global "field" in same class need to:
map<string,myobject> map = new hashmap<string,myobject>();
your method signature should include myobject instead of object , can use:
map.put(akey, anobject)
Comments
Post a Comment