# Greater than 10? You're not a good fit for us

• 10
• Locked
The Oddiozo transshipment center is looking for employees. The only requirement is this: employees must not have more than ten limbs (we don't know where this form of discrimination came from). We'll help them with a program that will create a set of numbers (Set ), add 20 different numbers, and then remove from the set all the numbers greater than 10.
You can't complete this task, because you're not signed in.
Shamil
Level 19 , Kyiv, Ukraine
11 July 2022, 21:06
Try Collection.removeif() method or through Iteretor.
ImDevin
Level 15 , Old Town, United States
29 April 2021, 02:36
wow, this was a super learning experience task. Found three different ways to solve this task. practiced writing it to gain familiarity. Nearly took all day, but it was worth it. Happy coding! :)
Desislava Petrova
Level 24 , Sofia, Bulgaria
17 February 2021, 10:10
set.removeIf(n -> (n > 10));
Nickolas Johnson
Level 8 , St. Louis, United States of America
20 November 2020, 16:04
set.removeAll came in super handy here
Karas Java Developer
16 September 2020, 00:21
Enhanced for loop in the second one, had two create an additional Set but it worked.
Liew
Level 10
11 May 2020, 07:48
why is it when u call iterator, to remove the element you call it. remove instead of set.remove(it) as according to hash set java API???
Level 27 , Spanish Town, Jamaica
30 April 2020, 06:17
I got this right using the removeIf method in the Set class. we haven't been taught that here, but I stumbled across it while reading some time ago and was itching to try it. for what we have been taught though, just: 1. create an iterator object to go through the set (a set doesn't have index numbers so there is no .get() method. 2. run the interation as long as there is another number in the set (.hasNext()) 3. if statement that removes numbers larger than 10, called by the iterator. cheers! :)
Andrei
Level 41
3 November 2020, 09:54
Have you also tried using iterator.remove(); ? I tried doing your way but I did not understand (from my research) how to use removeIf() function so I did it with remove.
Liliane Top
Level 17 , Amsterdam, Netherlands
16 February 2020, 18:45
I'm very confused about the usage of HashSet vs Set. In the given examples I encounter Set<String> set = new HashSet<String>(); but in the task above it gives an error with the return statement. When I changed this into: HashSet<String> set = new HashSet<String>(); it worked. I'm so confused. What is the difference? And why give examples if they do not work? Can anybody shed some light on this matter? Very much appreciated!
Andrei
Level 41
3 November 2020, 09:17
Hello! I have stumbled upon the same thing. Have you found any explanation for this? Thanks! :)
Turner
Level 11 , Pittsburgh, United States
30 August 2019, 05:38
Can I assume that a solution for removeAllNumbersGreaterThan10() - first, iterate through the set and set all numbers > 10 to a separate array then iterate through the array removing the set elements WITH NO CONCURRENCY issues fails the requirement is because of Time complexity? Not sure if Iteration<Integer> introduces a savings of Space complexity, but an extra for loop does NOT increase performance much beyond O(n). Can you explain what I am missing in why this solution is not allowed to pass? Please advise.
mani
Level 13 , Harpanahalli, India
28 June 2019, 12:41