I'm using a class and main of my own devising. To do the simulation I need to, I need to determine what object from an array of identical objects contains the greatest of a certain private field. For example,
Robot[] set = new Robot [7];
//initialize here, and do other stuff
At this point, I need to figure out which object within Robot has the greatest value of a certain field, which we'll call myBeepers
, and tell that Robot to run a method, which we'll call dropAllBeepers
. And that is where the problem lies, because
- How do I call Math.max for something like this, and then call the corresponding object?
- I need extremely efficient code (in terms of methods called, not execution time. It's complicated, but in short, I need to call as few methods as possible), and a for-loop would cost me an extreme amount of memory, so that's out of the question.
In short, how do I get this down to a single line? Something like:
Math.max (set.getBeepers()).dropAllBeepers();
Except this doesn't work because Math.max turns in a variable, not the object.