I've tried using an iterator as well as making a copy of the set, iterating through the original and removing from the copy and then returning the copy: nothing works. Please assist.
package com.codegym.task.task08.task0814;
import java.util.HashSet;
import java.util.Set;
import java.util.Iterator;
/*
Greater than 10? You're not a good fit for us
*/
public class Solution {
public static HashSet<Integer> createSet() {
// write your code here
HashSet<Integer> set = new HashSet<>();
for(int i = 1; i <= 20; i++)
{
set.add(i);
}
return set;
}
public static HashSet<Integer> removeAllNumbersGreaterThan10(HashSet<Integer> set) {
// write your code here
Iterator<Integer> itr = set.iterator();
while(itr.hasNext())
{
if(itr.next() > 10)
{
set.remove(itr);
}
}
return set;
}
public static void main(String[] args) {
}
}