How to remove value from HashSet in Java

1 Answer

0 votes
import java.util.*;

public class MyClass {
    public static void main(String args[]) {
        Set<String> letters = new HashSet<>(Arrays.asList("a", "b", "c", "d", "a", "a", "e"));
      
        System.out.println(letters); 
        
        letters.remove("a");
        
        System.out.println(letters); 
    }
}




/*
run:

[a, b, c, d, e]
[b, c, d, e]

*/

 



answered Feb 16, 2021 by avibootz

Related questions

1 answer 256 views
1 answer 275 views
1 answer 315 views
1 answer 272 views
272 views asked Feb 16, 2021 by avibootz
1 answer 245 views
245 views asked Oct 30, 2022 by avibootz
1 answer 216 views
1 answer 250 views
...