• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting the max value from the list

 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?


 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Suryanarayana Murthy Maganti
Greenhorn
Posts: 17
Hibernate Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeff. I will try first and if turns out wrong, i will seek your help.

 
reply
    Bookmark Topic Watch Topic
  • New Topic