Why we can't create the streams for map?
Asked
Active
Viewed 1,624 times
4
-
6Map does not implement Collection. – PM 77-1 Oct 10 '16 at 02:35
1 Answers
11
Streams cannot directly be created from maps because a map is not a collection. For further explanation on why a map is not a collection you can view this answer https://stackoverflow.com/a/2651833/2796463.
Maps in Java can be iterated in three ways:
- A set of keys
- A collection of values
- A a set of key value pairs
You need to specify which order you wish to iterate through the map before creating a stream
map.keySet().stream()
map.values().stream()
map.entrySet().stream()

Community
- 1
- 1

DragonAssassin
- 929
- 2
- 10
- 14
-
1Good answer, but it would be even stronger if you in a concrete way answered the original question (_Why we can't create the streams for map?_). – Magnilex Oct 10 '16 at 08:09