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 173 views
1 answer 184 views
1 answer 227 views
1 answer 194 views
194 views asked Feb 16, 2021 by avibootz
1 answer 150 views
150 views asked Oct 30, 2022 by avibootz
1 answer 127 views
1 answer 165 views
...