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));
		// });

	}
}
相关推荐
来让爷抱一个1 小时前
Python 异步里混用同步库,事件循环被卡住的全过程
开发语言·python
kingx31 小时前
Bugku 3122 谷歌小恐龙题解:纯离线逆向 Vault 的 AES-GCM 加密资源(附 Python 解密器)
java·逆向·ctf·bugku·aes-gcm
DevOpenClub3 小时前
职教高考控制线 API:招生类别枚举、筛选与空分数含义
java·数据库·高考
心祭丫丫4 小时前
【每天一个 Python 小案例17】Python 实现通讯录
开发语言·人工智能·笔记·python·学习
露天赏雪4 小时前
第3篇:Sentinel熔断降级实战:大模型接口抖动时的服务兜底方案
java·开发语言·人工智能·spring boot·spring·servlet·sentinel
天天被压力4 小时前
【A股分钟级高频数据完全手册 #06】北交所分钟级数据接口:京市股票Pro版最新分时
java·人工智能·python
天天被压力4 小时前
【A股分钟级高频数据完全手册 #05】指数历史分钟数据接口:Pro版沪深指数分时回放
java·人工智能·python
captain3765 小时前
▲统一功能——DispatcherServlet源码分析
java·spring·java-ee·log4j·maven
金銀銅鐵5 小时前
JDK 21 中 List.of 的实现细节:从 List12 到 ListN
java·后端·ai编程
yeccheng6 小时前
MySQL 索引超详解:从底层 B+ 树到面试高频考点
java·开发语言·jvm·mysql·面试