Results 1 to 5 of 5
Thread: uniq
- 04-06-2010, 06:29 PM #1
uniq
In one word, what's wrong with this method?
Idea is that it should return a list that contains no duplicates
In anticipation of why i think there is something wrong with it, the following is a warning i get "Type safety: Unchecked cast from HashSet<String> to List<String>"Java Code:private List<String> uniqueArguments(ArrayList<String> arrayList) { List<String> noDups = (List<String>) new HashSet<String>(arrayList); return noDups; }
And also, it does not work :(
Exception in thread "main" java.lang.ClassCastException: java.util.HashSet cannot be cast to java.util.List
1 more comment, sysouts work and print what's expected, but stillJava Code:private List<String> uniqueArguments(ArrayList<String> arrayList) { System.out.println(arrayList); HashSet<String> noDups = new HashSet<String>(arrayList); System.out.println(noDups); return (List<String>) noDups; }
Exception in thread "main" java.lang.ClassCastException: java.util.HashSet cannot be cast to java.util.ListLast edited by mac; 04-06-2010 at 06:38 PM.
- 04-06-2010, 06:39 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You cannot cast Hashset to List.
- 04-06-2010, 06:51 PM #3
Ok ... any advise on how to go about it?
Have a List, need to check if it contains unqiue elements
- 04-06-2010, 08:15 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
- 04-07-2010, 03:00 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks