2022-11-16

I need to input IntFunction such that Collections.toArray(IntFunction

I have a Set of Integer:

Set<Integer> itemSet = new HashSet<Integer>();
itemSet.add(1);
itemSet.add(3);
itemSet.add(5);

I want to convert it into an array of Integer where the value of each element in the array is double the value of the corresponding element in original Set. According to the above example, the array elements should be:

2, 6, 10

I tried:


Integer[] itemArr1 = itemSet.toArray((val) -> {
            Integer[] it = new Integer[]{val*2};
            return it;
            }
        );

but the values are not getting doubled.



No comments:

Post a Comment