Languages
[Edit]
EN

Java - iterate over Set and remove indicated items

0 points
Created by:
Jax
388

In this article, we would like to show you how to iterate over Set and remove indicated items in Java.

 

1. Using iterator

Edit

In this example, we use an iterator to remove indicated item from the letters HashSet.

Output:

2. Using Collection.removeIf()

Edit

In this example, we use Java 8 removeIf() method to remove indicated element from the letters HashSet.

Output:

3. Using stream

Edit

In this example, we create an instance of a stream from the letters HashSet, filter each element and collect the result in the new filteredLetters.

Output:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join