Here you can find the source of setToArray(Set
public static int[] setToArray(Set<Integer> set)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; public class Main { /**Sorted in ascending order.*/ public static int[] setToArray(Set<Integer> set) { List<Integer> l = new ArrayList<Integer>(set); Collections.sort(l);// w w w. j a v a2s .c o m int[] intArray = new int[l.size()]; for (int i = 0; i < intArray.length; ++i) { intArray[i] = l.get(i); } return intArray; } }