Results 1 to 6 of 6
Thread: how to sort an arraylist?
- 03-18-2010, 10:48 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
how to sort an arraylist?
that is my code... im trying to sort arrayList and im getting this errorJava Code:private void add(ArrayList v) { ArrayList arrayList = new ArrayList(); for(int j=0; j<v.size(); j++) { arrayList.add(v.get(j)); } for(int i=0;i<ret.size();i++) { if(Collections.sort(arrayList) ==ret.get(i)) ret.add(Collections.sort(arrayList)); } }
"'void' type not allowed here"
please help
-
This code doesn't make much sense to me, sorry. What are you trying to do here? If you're trying to sort an ArrayList, you simply call Collections.sort(myList) and be done with it. Note that the items in the arraylist should implement the Comparable interface.
- 03-18-2010, 11:02 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
nvm
lol i got it...all i did was first sort the array then use the array in the if statements
-
- 03-19-2010, 03:51 AM #5
Look into SortedSet subclasses, such as TreeSet. Note that Set requires that the elements be unique, unlike a list. You can then just do something like
Java Code:SortedSet sortedSet = new TreeSet(myArrayList);
- 03-19-2010, 08:01 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Using Merge Sort to sort an ArrayList of Strings
By coldfire in forum New To JavaReplies: 3Last Post: 03-13-2009, 01:03 AM -
how to sort "name" arraylist with its phone & address?
By anthrax in forum New To JavaReplies: 2Last Post: 02-02-2009, 11:29 AM -
How to sort a list using Bubble sort algorithm
By Java Tip in forum AlgorithmsReplies: 3Last Post: 04-29-2008, 08:04 PM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM -
how to sort
By Feng in forum New To JavaReplies: 1Last Post: 11-20-2007, 06:56 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks