C++
Say we insert 5 objects into a set.Each object has a id and a name as the attributes.We can get an iterator to the element we are searching for by say
int main()
{
set<Obj*> setObj;
Obj *objA = new Obj(10,"P"); Obj * objB = new Obj(20,"L");
setObj.insert(objA);setObj.insert(objB);
set<Obj*>::iterator it = setObj.find(objA);
if( it > 0 )
it->name = "New name";
}
//Hope the idea is clear.I basically can change the non key part of the object in the set .in this case the obj class has key as id
Now in Java since we dont have set offering find, is the only way to do so is by looping through?
apologies if the syntax is not exactly right.Havent compiled the code