Answers for "how to convert an Hashset of integers into array"

1

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));
    }
}
Posted by: Guest on June-01-2020

Code answers related to "how to convert an Hashset of integers into array"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language