Java 8新特性之stream流的练习

加油,新时代打工人!

java 复制代码
import org.junit.jupiter.api.Test;
import org.omg.CORBA.StringDefIRHelper;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.ObjectUtils;
import sun.security.util.AuthResources_it;

import java.util.*;


@SpringBootTest
class InterfacesApplicationTests {

	@Test
	void contextLoads() {
	}

	public static void main(String[] args) {
		HashMap<String,String> map =new HashMap<>();
		HashMap<String,String> map1 =new HashMap<>();
		map.put("SSTYPE","1");
		map.put("SSCODE","11");
		map.put("SSNAME","小明");
		map.put("SSJB","2");
		map1.put("SSTYPE","1");
		map1.put("SSCODE","11");
		map1.put("SSNAME","小明");
		map1.put("SSJB","2");
		List<HashMap<String,String>> map2 =new ArrayList<>();
		map2.add(map);
		map2.add(map1);
		// System.out.println("方式二>>map.entrySet().stream.forEach()遍历---Stream流遍历");
		// for(HashMap<String,String> map3 :map2){
		// 	map3.entrySet().stream().forEach((Map.Entry<String,String> entry) -> {
		// 		System.out.print(entry.getKey());
		// 		System.out.println(entry.getValue());
		//
		// 	});
		// }
		int [] index={0};
		System.out.println("方式一>>map.entrySet().stream.forEach()遍历---Stream流遍历");
		for (int j = 0; j < map2.size(); j++) {
			HashMap<String,String> map4 =new HashMap<>();
			// Iterator<Map.Entry<String,String>> it = map2.get(j).entrySet().iterator();
			// while (it.hasNext()){
			// 	Map.Entry<String,String> itEntry = it.next();
			// 	map4.put(itEntry.getKey() + j,itEntry.getValue());
			// 	it.remove();
			// }

			map2.get(j).entrySet().stream().forEach((Map.Entry<String,String> entry) -> {
				System.out.println("索引"+index[0]);
				if((("SSTYPE").equals(entry.getKey())) && ("1".equals(entry.getValue()))){
					map4.put(entry.getKey(),entry.getValue());
				}else{
					map4.put(entry.getKey()+""+ index[0],entry.getValue());
				}
				index[0]++;
			});
			// System.out.println(map4.toString());
		}
		// System.out.println("map.keySet().stream.forEach()遍历---Stream流遍历");
		// map.keySet().stream().forEach(key -> {
		// 	System.out.println(map.get(key));
		// });

	}
}
相关推荐
程序猿乐锅22 分钟前
从0-1一文详解RabbitMQ
java·分布式·后端·中间件·rabbitmq·ruby
考虑考虑4 小时前
JDK26中的List.ofLazy()
java·后端·java ee
小蒜学长4 小时前
基于SpringBoot的公寓报修管理系统的设计与实现(代码+数据库+LW)
java·spring boot·后端·公寓报修管理系统·多角色协同
for_ever_love__4 小时前
MySQL 主从复制讲透:binlog 原理、搭建步骤与读写分离
java·数据库·mysql·binlog·读写分离·原理·主从复制
Ada's4 小时前
【计算机基础系列】003:Python数据结构
开发语言·数据结构·python
2601_962885725 小时前
如何用 Python 计算 TRIX 三重指数平滑均线指标?
开发语言·python
还卿一钵无情泪5 小时前
Unsloth 微调 构建自己的大模型 没有GPU也能微调
linux·开发语言·人工智能·python·大模型·nlp·unsloth
小π军6 小时前
操作系统面试题
java·linux·服务器
倔强的石头1067 小时前
应用账号最小权限实践:读写账号、报表账号、运维账号分层
java·运维·开发语言