File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Getting the MAX int value within a list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting the MAX int value within a list" Watch "Getting the MAX int value within a list" New topic
Author

Getting the MAX int value within a list

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

I have an object called req. Within the req object I have a LIST reqItems. Within this list I have an INT property called lineitemcount.

I am needing to acquire the MAX int value of lineitemcount within this list.

I'm needing help as to how to accomplish that. This is the code I have so far:



Any help or direction would be appreciated. Thanks.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Set a variable max = 0. For each item, compare lineitemcount to max. If it's greater than max, set max to the value of lineitemcount, otherwise do nothing.

When you get to the end of the list, max will be the maximum value of lineitemcount.


[Jess in Action][AskingGoodQuestions]
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

Ernest,

Thanks so much for the reply. I'll do that.

Thanks so much for pulling me out of the weeds. Regards.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Note that that strategy works only if you are sure that the maximum is a positive number or 0.

Can you think of a way to do it if it was possible that the maximum value was a negative number?


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Originally posted by Garrett Rowe:
Note that that strategy works only if you are sure that the maximum is a positive number or 0.

Can you think of a way to do it if it was possible that the maximum value was a negative number?


Garrett is right, of course; but I took into account that the variable is named "linenumbercount."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting the MAX int value within a list