import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Author liangjunwei
* @Date 2022/1/21 17:18
*/
public class MapToList {
public static void main(String[] args) {
Map<String,String> map = new HashMap<>(16);
map.put("600519","贵州茅台");
map.put("601398","工商银行");
map.put("300750","宁德时代");
map.put("002415","海康威视");
map.put("09988","阿里巴巴");
map.put("00700","腾讯控股");
List<Object> list = map.entrySet().stream().map(ent -> ent.getKey()+":"+ent.getValue())
.collect(Collectors.toList());
list.forEach(listFor -> System.out.println(listFor));
System.out.println("map数据格式:" + map);
System.out.println("list数据格式:" + list);
}
}
Java8使用stream将Map转成List的方法
于 2022-01-20 13:16:04 首次发布