Lambda遍歷Map集合


  1. 實體類
	@Data
	class Student01 {
		private Integer id;
		private String name;

		Student01(Integer id, String name) {
			this.id = id;
			this.name = name;
		}
	}
  1. 遍歷Map集合
	Map<String, Student01> map = new HashMap<>();
	map.put("甲班", new Student01(1, "張三"));
	map.put("乙班", new Student01(2, "李四"));

	map.forEach((key, value) -> {
		if (!"甲班".equals(key)) {
			System.out.println(value);
		}
	});
	//TODO: Student01(id=2, name=李四)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM