HashSet remove element upon condition
问题 I have a HashSet containing tens of thousands of rectangles, when the Y is less than 0 I want to remove it from the HashSet right now my code looks like the following for (Rectangle p : point) { if(p.y<0){ point.remove(p); System.out.println("removing p"); continue; } Here is the code for my HashSet public HashSet<Rectangle> point; it never removes the Rectangle that has a Y less than 0 but the System.out.println("removing p"); runs. 回答1: The problem is HashSet does not allow you to remove