当前位置: 首页 > news >正文

hashmap使用

hashmap作为dao对象存储数据库数据

list是把每一个数据库的字段都映射了,而hashmap则是唯一id:数据库字段作为key

hashmap遍历方式


public class Main {//使用迭代器(Iterator)EntrySetpublic static void main(String[] args) {// 创建并赋值 HashMapMap<Integer, String> map = new HashMap();map.put(1, "Java");map.put(2, "JDK");map.put(3, "Spring Framework");map.put(4, "MyBatis framework");map.put(5, "Java");// 遍历Iterator<Map.Entry<Integer, String>> iterator = map.entrySet().iterator();while (iterator.hasNext()) {Map.Entry<Integer, String> entry = iterator.next();System.out.println(entry.getKey());System.out.println(entry.getValue());}}//ForEach EntrySet@Testpublic void test1(){// 创建并赋值 HashMapMap<Integer, String> map = new HashMap();map.put(1, "Java");map.put(2, "JDK");map.put(3, "Spring Framework");map.put(4, "MyBatis framework");map.put(5, "Java");// 遍历for (Map.Entry<Integer, String> entry : map.entrySet()) {System.out.print(entry.getKey());System.out.print(entry.getValue());}}//ForEach KeySet@Testpublic void test2(){// 创建并赋值 HashMapMap<Integer, String> map = new HashMap();map.put(1, "Java");map.put(2, "JDK");map.put(3, "Spring Framework");map.put(4, "MyBatis framework");map.put(5, "Java");// 遍历for (Integer key : map.keySet()) {System.out.print(key);System.out.print(map.get(key));}}//Lambda@Testpublic void test3(){// 创建并赋值 HashMapMap<Integer, String> map = new HashMap();map.put(1, "Java");map.put(2, "JDK");map.put(3, "Spring Framework");map.put(4, "MyBatis framework");map.put(5, "Java中文社群");// 遍历map.forEach((key, value) -> {System.out.print(key);System.out.print(value);});}//Streams API 单线程@Testpublic void test4(){// 创建并赋值 HashMapMap<Integer, String> map = new HashMap();map.put(1, "Java");map.put(2, "JDK");map.put(3, "Spring Framework");map.put(4, "MyBatis framework");map.put(5, "Java中文社群");// 遍历map.entrySet().parallelStream().forEach((entry) -> {System.out.print(entry.getKey());System.out.print(entry.getValue());});}
}
http://www.lryc.cn/news/170752.html

相关文章:

  • Centos7配置国内yum源
  • C#中async/await的线程ID变化情况
  • 网络安全—黑客技术—自学笔记
  • 功夫再高也怕菜刀。多年经验,会独立开发的机器视觉工程师,技术太强,但是找工作能力差劲
  • numpy的多项式函数: `poly1d`
  • Python灰帽编程——错误异常处理和面向对象
  • 【20230919】win11无法删除Chrome注册表项
  • TCP/IP客户端和服务器端建立通信过程
  • Python ---使用Fake库向clickhouse造数据小案例
  • 09MyBatisX插件
  • 使用 Messenger 跨进程通信
  • Spring Cloud Gateway
  • JVM 优化技术
  • 【MySQL系列】- MySQL自动备份详解
  • 指针笔试题讲解-----让指针简单易懂(2)
  • 使用windbg分析dump文件的方法
  • 【论文阅读 07】Anomaly region detection and localization in metal surface inspection
  • SSM - Springboot - MyBatis-Plus 全栈体系(十一)
  • 深度剖析贪心算法:原理、优势与实战
  • Docker搭建DNS服务器--use
  • “顽固”——C语言用栈实现队列
  • linux内网渗透
  • 还没用熟 TypeScript 社区已经开始抛弃了
  • 2023年9月19日
  • PowerDesigner 与 mysql 同步数据
  • [python 刷题] 271 Encode and Decode Strings
  • [QT]day3
  • 《PostgreSQL事务管理深入解析》
  • 深度分析Oracle中的NULL
  • Python入门教学——类和对象