Looking at the java api for java collections framework, I could not find toArray() method in HashSet, there is toArray() method in abstract class Set.
class Ideone {
public static void main (String[] args) throws java.lang.Exception {
Set x = new HashSet();
x.add(4);
//ArrayList<Integer> y = x.toArray(); this does not work !
int[] y = x.toArray();//this does not work!
System.out.println(x.toArray());//this gives some weird stuff printed : Ljava.lang.Object;@106d69c
}
}
How do I convert hashset into array if there is no toArray() specified?
Object[], just printing that is giving you the typical java output if the toString is not properly overwritten. And anObject[]is not implicitly convertible toint[].