No pointers...hmm...
Author |
Message |
Martin
|
Posted: Thu Nov 04, 2004 3:59 pm Post subject: 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? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dan
|
Posted: Thu Nov 04, 2004 4:05 pm Post subject: (No subject) |
|
|
have u tryed just retruning the object? lol
ie. return objectName
or am i missing the point of your post? |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
rizzix
|
Posted: Thu Nov 04, 2004 4:08 pm Post subject: (No subject) |
|
|
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)
code: | StoringObject obj = objects[0];
for (StoringObject o : objects)
if (obj.getNumber() < o.getNumber())
obj = o; |
|
|
|
|
|
|
Martin
|
Posted: Thu Nov 04, 2004 4:09 pm Post subject: (No subject) |
|
|
Yeah, nevermind, it was a dumb question. I'm just slow lately. |
|
|
|
|
|
|
|