convert hashset to array

Solutions on MaxInterview for convert hashset to array by the best coders in the world

showing results for - "convert hashset to array"
Sofia
31 Jul 2016
1//	First of all, you shouldn't use raw types.
2//	Use :
3	Set<Integer> set = new HashSet<>();
4	set.add(4);
5	set.add(1);
6//	Then convert to array :
7	Integer[] arr = x.toArray(new Integer[set.size()]);
8//	Using x.toArray() would give you an Object[].