Results 1 to 6 of 6
Thread: Looping ArrayList
- 05-05-2008, 12:50 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 2
- Rep Power
- 0
- 05-05-2008, 12:55 PM #2
array t1={2,6,4,9}
what is array is this a Class
java.sql.Array or reflect.Array :confused:i am the future
- 05-05-2008, 02:00 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
In simple way, loop the array on each element and at the same time maintain two variables to hold largest values.
- 05-06-2008, 02:15 PM #4
Member
- Join Date
- Apr 2008
- Posts
- 3
- Rep Power
- 0
...in case you think of replacing the simple array with a ArrayList obj you can very well go for the Collections.max(Collection obj) to get the maximum value.
Regards,
Abhishek.
- 05-07-2008, 03:45 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes, it's true. But he is looking to do it in a loop.
- 05-07-2008, 03:55 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Something like this may help in that sense, I think.
Java Code:private void findMax(ArrayList arl) { int max = 0; for(int i = 0; i < arl.size(); i++) { if(Integer.parseInt((String) arl.get(i)) > max) { max = Integer.parseInt((String) arl.get(i)); } } System.out.println(max); }
Similar Threads
-
Can't solve error message while looping
By BHCluster in forum New To JavaReplies: 15Last Post: 04-22-2008, 10:51 AM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM -
ArrayList
By kizilbas1 in forum New To JavaReplies: 1Last Post: 01-12-2008, 08:48 PM -
Java Looping and decision
By susan in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 04:29 AM -
looping a function
By Username in forum New To JavaReplies: 2Last Post: 07-30-2007, 05:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks