0

Hi, i need to find the max value of ArrayList<ArrayList>. I don't know whether it is possible or not? Can anyone please give me some suggestion.

Any help from you will highly be appreciated....
Thanks.

4
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by sumprit
0

Check Collections.max Sample usage:

ArrayList<Integer> al = new ArrayList<Integer>();
//add values
Object o = Collections.max(al);
System.out.print("Max: " + o );

Hope this helps

Edited by kekkaishi: n/a

0

Thanks for your reply. I tried this but i found an error saying...

"Bound mismatch: The generic method min(Collection<? extends T>) of type Collections is not applicable for the arguments (ArrayList<ArrayList>). The inferred
type ArrayList is not a valid substitute for the bounded parameter <T extends Object & Comparable<? super T>>"

Actually i have 3 arraylist in 1 arraylist. Now i need to find the max of the the 3 arraylist separately.

0

Oh I mistakenly disregarded <ArrayList> part. If that is the case, do you want to get the maximum in terms of the size of the ArrayList?

0

No actually i want the values contained in the 3 arraylist in terms of string type, i need to use them to display in 3 JLabels. Please give me some suggestion...

Thanks.

0

Loop the ArrayList. Then each element is also an ArrayList. So take each element of the first ArrayList and loop that to in an inner loop:

ArrayList<ArrayList> [B]list[/B]
loop [B]list[/B] {
  take each array_list inside [B]list[/B]
  loop that array_list {
    // do whatever
  }
}

But I don't think that it is good practice to have an ArrayList of array lists

0

Thank you i got the idea. Now i can do.... Thanks for your help...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.