
-----------------------------------
Martin
Thu Nov 04, 2004 3:59 pm

No pointers...hmm...
-----------------------------------
Okay, I have a set of 5 objects, each of which is storing a number. I need to return the object associated with the lowest number. With C++, I could use a pointer, but how would I do this with Java?

-----------------------------------
Dan
Thu Nov 04, 2004 4:05 pm


-----------------------------------
have u tryed just retruning the object? lol

ie.     return objectName


or am i missing the point of your post?

-----------------------------------
rizzix
Thu Nov 04, 2004 4:08 pm


-----------------------------------
assuming you define a method for each object to retrive the value of the stored number as getNumber

then all you need to do is probably something like this (assuming that the 5 objects are in an array called objects and StoringObject is the name of the class that defines these objects)

StoringObject obj = objects[0];

for (StoringObject o : objects)
    if (obj.getNumber() < o.getNumber())
        obj = o;

-----------------------------------
Martin
Thu Nov 04, 2004 4:09 pm


-----------------------------------
Yeah, nevermind, it was a dumb question. I'm just slow lately.
