简体   繁体   中英

Why streams cannot be created for map in Java8?

为什么我们不能为地图创建

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:

  1. A set of keys
  2. A collection of values
  3. A a set of key value pairs

You need to specify which order you wish to iterate through the map before creating a stream

  1. map.keySet().stream()
  2. map.values().stream()
  3. map.entrySet().stream()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM