Vector.toArray() has the following syntax.
public Object [] toArray()
In the following code shows how to use Vector.toArray() method.
/* ww w . j a v a 2 s .c o m*/ import java.util.Arrays; import java.util.HashSet; import java.util.Set; public class Main { public static void main(String[] args) { String elements[] = { "M", "N", "O", "P", "Q" }; Set set = new HashSet(Arrays.asList(elements)); String[] strObj = new String[set.size()]; strObj = (String[]) set.toArray(strObj); for (int i = 0; i < strObj.length; i++) { System.out.println(strObj[i]); } System.out.println(set); } }
The code above generates the following result.