Results 1 to 4 of 4
Thread: Collections help.
- 03-14-2011, 10:32 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 6
- Rep Power
- 0
Collections help.
Hey, I'm writing a program that is using an arraylist.
I've used Collections.max(arraylist) and Collections.min(arraylist) to return the longest and shortest elements in the arraylist. However, the shortest an element in the arraylist can be is 1, because otherwise the element is empty and is skipped when being counted.
How can I get my program to include the empty elements when searching for the shortest element?
thanks for your help, I know it's probably a simple answer and only one or two lines of code but I'm struggling to think of it
- 03-14-2011, 10:53 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
I need more detail. What is your arraylist holding? Also, an arraylist readjusts the size when you add or remove something. So there shouldn't be empty elements.
- 03-14-2011, 11:02 PM #3
There are 2 max and 2 min methods. The second version of each takes a Comparator as a parameter. Therefore write your own Comparator to compare the elements however you like.
- 03-14-2011, 11:14 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Qustion about collections
By nn12 in forum New To JavaReplies: 2Last Post: 01-10-2011, 03:36 PM -
Help collections
By nikosv in forum New To JavaReplies: 8Last Post: 12-13-2010, 05:29 PM -
Collections
By Cbani in forum New To JavaReplies: 3Last Post: 02-16-2010, 02:46 PM -
Collections Help
By Dr Gonzo in forum New To JavaReplies: 0Last Post: 12-07-2008, 09:15 PM -
Performance Of Collections
By thomasprabu in forum Advanced JavaReplies: 0Last Post: 01-05-2008, 11:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks