Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Return max value in List  RSS feed

 
El Bel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have written the following to return the max value in a list (between startTime and endTime), however it returns nothing. Any ideas why? Thank you!

 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you don't post a short, self contained, correct and compileable example, it can be very hard to tell what's wrong.

The only thing I'd suggest is to sprinkle in some System.out.println statements to see what your code is doing.  Are you actually getting into your maxMatchingReadings method? Do you enter your If statement? How many times? Does your while loop run? how many times? Print out every time your max value is incremented. print out what reportList.get(max).getValue();   returns inside the method, along with what "max" is at that point.

My GUESS is that max is set to something outside your list size, so it's not actually returning an int, but probably throwing an exception that might be getting swallowed somewhere.
 
Carey Brown
Bartender
Posts: 2992
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have two nested loops. Only the outer for() loop is necessary. The rest of the logic should be handled in an if() statement.
If none of the items in the list are within range you return list[0] which would be incorrect.
Max should be 'i' not 'i+1'.
 
Paul Clapham
Sheriff
Posts: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would help if you explained what you mean by "nothing". The code you posted can't return nothing, unless it throws an exception. It might conceivably return something which looks like nothing, like maybe an empty string, but it must return something.
 
El Bel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
El Bel wrote:Have written the following to return the max value in a list (between startTime and endTime), however it returns nothing. Any ideas why? Thank you!

 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have any update on your problem?  Your last post looks like a copy of the first post.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!