• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting the MAX int value within a list

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic