So, I have been doing an online code problem on this website called Codewars and I'm having some problem with my code. When I was using the set interface, it gave me an error:
/workspace/java/src/FindOdd.java:16: error: no suitable constructor found for HashSet(List<int[]>)
Set<Integer> keys = new HashSet<Integer>(Arrays.asList(a));
^
constructor HashSet.HashSet(Collection<? extends Integer>) is not applicable
(argument mismatch; inferred type does not conform to upper bound(s)
inferred: int[]
upper bound(s): Integer,Object)
constructor HashSet.HashSet(int) is not applicable
(argument mismatch; no instance(s) of type variable(s) T exist so that List<T> conforms to int)
where T is a type-variable:
T extends Object declared in method <T>asList(T...)
Note: /workspace/java/src/FindOdd.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
(by the way, my code isn't finished, tell me if I have to finish it first or not)
this is my code:
import java.util.*;
public class FindOdd {
public static int findIt(int[] arr) {
LinkedHashMap apearanceCount = new LinkedHashMap();
for(int i = 0; i < arr.length; i++){
if(apearanceCount.containsKey(arr[i])){
int amount = Integer.parseInt(apearanceCount.get(arr[i]).toString()) + 1;
apearanceCount.put(arr[i], amount);
} else {
apearanceCount.put(arr[i], 1);
}
}
Set<Integer> keys = new HashSet<Integer>(Arrays.asList(arr));
}
}
Please help me!
(for people who think this is a duplicate, from what I know, arrays converting to sets isn't the same as converting arrays to lists. If I am wrong, answer in the comments. ;) )