hashset to array int java code example
Example: convert hashset to int array java
import java.util.Arrays;
import java.util.Set;
import java.util.HashSet;
class Main
{
// Program to convert set of integer to array of int in Java
public static void main(String args[])
{
Set<Integer> ints = new HashSet<>(Arrays.asList(1, 2, 3, 4, 5));
int[] primitive = ints.stream()
.mapToInt(Integer::intValue)
.toArray();
System.out.println(Arrays.toString(primitive));
}
}