Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Norm

Thread: Max and Min in ArrayList

  1. #1
    qwe
    qwe is offline Member
    Join Date
    Nov 2014
    Posts
    13
    Rep Power
    0

    Question Max and Min in ArrayList

    Hi Everyone.

    I have an ArrayList with String, String, Double.
    From another class I would like to print minimum and maximum including the first String name.
    I have tried with import java.util.Collections; but that didn't work.
    Any ideas? Thanks!

    Java Code:
    ArrayList<List>list = new ArrayList<List>();
    		
    	list.add(new List("Abc","Cba",1));
    	list.add(new List("Bca","Bca",5));
    	list.add(new List("Cba","AcB",2));
    I would like the result to look like:

    Minimum: Abc 1
    Maximum: Bca 5

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Max and Min in ArrayList

    What is the definition of the List class? Does it have methods to test its contents?

    The normal way to find objects in an ArrayList is to use a loop to go through the list, get each object in the list and test it against some criteria.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    qwe
    qwe is offline Member
    Join Date
    Nov 2014
    Posts
    13
    Rep Power
    0

    Default Re: Max and Min in ArrayList

    The class List only has set and get methods.
    Okay, so something like. If index 0s double is greater than all the other double then print its value, to find maximum ? Ich?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Max and Min in ArrayList

    Note: Using the same name for your class as one of the Java SE classes makes for confusion. It'd be better if your class's name was different.
    qwe likes this.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 10-11-2013, 06:18 PM
  2. Replies: 0
    Last Post: 09-21-2013, 12:28 AM
  3. Replies: 12
    Last Post: 07-07-2011, 09:49 PM
  4. Replies: 7
    Last Post: 11-22-2010, 02:26 PM
  5. Replies: 2
    Last Post: 04-21-2008, 12:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •