• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting the max value from the list  RSS feed

 
Maganti Suryanarayana Murthy
Greenhorn
Posts: 10
Eclipse IDE Hibernate Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have one list as List<Message> messages=new ArrayList<Message>, where Message is a class which has four properties like, string msg, string shortlist, integer severtity, string errormsg

Message
{
String msg;
Stirng shortlist;
integer severity;
String errormsg;}

One more class is Messages. java

Where i have declared List<Message> messages=new ArrayList<Message>.

For this getter and setters are written

I have a method in Messages.java as

addList(String msg, String shortlist, integer severity, String errormsg)
{
Message m=new Message(String msg, String shortlist, integer severity, String errormsg)
{
this.msg=msg;
this.shortlist=shortlist;
this.severity=severity;
this.errormsg=errormsg;
}
messages.add(m);
}

One more method called as
getSeverity()
{
int severity;

// How to get max value from messages list ?. I am not getting solution here. List<Message> messages contains 3 numbers as severity i.e, assume 3, 5, 4. I have to use for each or iterator and find the max value ? How its done ?

return severity;
}

My question is how to get all the severities in the getSevertiy() from messages (which is a list) and find the max value ?


 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you need to figure out how you'd do it "by hand." Imagine you have a row of boxes, and each box has a piece of paper in it, and each paper has names and values written on it, like "msg=hello, severity=1". You need to start by describing very clearly and precisely the very simple, basic steps you would find the maximum value for severity in that situation. Once you've done that, you can translate it easily to Java. If something doesn't translate easily, you probably need to break that step down into simpler, more precise sub-steps.
 
Maganti Suryanarayana Murthy
Greenhorn
Posts: 10
Eclipse IDE Hibernate Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeff. I will try first and if turns out wrong, i will seek your help.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!