Re: CIAO, How can I sort an ArrayList<K> of Generic Types ?
- From: Vivien Barousse <barousse.vivien@xxxxxxxxx>
- Date: 21 May 2008 15:02:43 GMT
On Wed, 21 May 2008 06:38:06 -0700, Giordano wrote:
"Ciao" (Hi) to everyone,
please can you tell me how can I sort an ArrayList<K> of generic types ?
If this arraylist were of this kind, ArrayList<String>, I could sort it
simply using this instruction:
ArrayList<String> list = new ArrayList<String>();
java.util.Collections.sort ( list );
but, in my case, i see that i cannot sort in this same way when i use an
arraylist of generic types.. like this one:
ArrayList<K> list = new ArrayList<K>(); /* ERROR --> */
java.util.Collections.sort ( list );
/* ERROR --> */ javac myProva.java
.\myIndexedTreeMap.java:46: cannot find symbol symbol : method
sort(java.util.ArrayList<K>) location: class java.util.Collections
Collections.sort (list);
^
1 error
Thanks if you can give me any help for my question ? Ciao
Hi,
Collections.sort is expecting a List containing objects implementing the
Comparable interface.
Did your K class implements Comparable ?
Hope this helps,
Vivien Barousse
.
- Follow-Ups:
- Re: CIAO, How can I sort an ArrayList<K> of Generic Types ?
- From: Giordano
- Re: CIAO, How can I sort an ArrayList<K> of Generic Types ?
- References:
- CIAO, How can I sort an ArrayList<K> of Generic Types ?
- From: Giordano
- CIAO, How can I sort an ArrayList<K> of Generic Types ?
- Prev by Date: Re: CIAO, How can I sort an ArrayList<K> of Generic Types ?
- Next by Date: Re: CIAO, How can I sort an ArrayList<K> of Generic Types ?
- Previous by thread: Re: CIAO, How can I sort an ArrayList<K> of Generic Types ?
- Next by thread: Re: CIAO, How can I sort an ArrayList<K> of Generic Types ?
- Index(es):
Relevant Pages
|
|