aspose 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 Java 8 in Action this week in the Java 8 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: 386

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: 24168
    
  30

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: 386

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: 24168
    
  30

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
 
Similar Threads
getting items stored in a vector?
Listbox
What's wrong with my code?
How to add a merge array from 2 others arrays and print it
Convert decimal value to binary