I think i misunderstood the application of HashMap when i was rewriting parts of my code to make it more maintainable.
joints
is a HashMap containing a set of objects identified by a String
:
private HashMap<String, SomeObject> joints = new HashMap(5, 1);
Population of the HashMap is straightforward enough via the put()
method. However I now need to run a method on each of them. The below code produces a syntax error at the first period, but i believe it illustrates what I am trying to do.
joints.("knee").someMethod(someValue);
joints.("hip").someMethod(someOtherValue);
joints.("shoulder").someMethod(someOtherValue);
joints.("neck").someMethod(someOtherValue);
joints.("elbow").someMethod(someOtherValue);
What would be a valid/correct equivalent? of the above? I am thinking get() the object, delete it from the map, modify the object, put() it back into the HashMap.
While a foreach would be a step closer, this is a moot approach as the arguements for someMethod() are different for each object.