Java collection (data conversion between list collection and map collection)

Specific requirements are as follows:

Function 1: define the method public void listtomap() {} to encapsulate the student element in the list into the map

1) use the construction method student (int ID, string name, int age, string sex) to create multiple student information and add it to the list

2) traverse the list and output the information of each student

3) put the data in the list into the map, use the student's ID attribute as the key, and use the student object information as the value

4) traverse the map and output the key and value of each entry

Function 2: define the method public void maptolist() {} to encapsulate the student mapping information in the map into a list

1) create an entity class studententry, which can store the information of each entry in the map

2) use the construction method student (int ID, string sex) to create multiple student information, and use the student's ID attribute as a key to store it in the map

3) create a list object, and each element type is studententry

4) put each entry information in the map into the list object

1、 Create student object

                   Student_3( id, .id = .name = .age = .sex =                       setId( .id =     .name =     setAge( .age =     .sex =      "["+id +" "+ name +" "+ age +" "+ sex+"]"    } 

  二,创建测试类

<div class="cnblogs_code">

                  List 
                                                                                                                                                                                     
                                                                                                                                                                                       list = 
                                                                                                                                                                                       ArrayList<>   Map 
                                                                                                                                                                                           
                                                                                                                                                                                             map = 
                                                                                                                                                                                             HashMap<>     Iterator 
                                                                                                                                                                                                     
                                                                                                                                                                                                       it = 
                                                                                                                                                                                                          Student_3 stu =       Set 
                                                                                                                                                                                                                        
                                                                                                                                                                                                                        
                                                                                                                                                                                                                          > entrySet = 
                                                                                                                                                                                                                           (Entry 
                                                                                                                                                                                                                             
                                                                                                                                                                                                                                         Map< Integer,Student_3> map =  HashMap<>   List 
                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                      list = 
                                                                                                                                                                                                                                                      ArrayList<>       Set 
                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                   > entrySet = 
                                                                                                                                                                                                                                                                    (Entry 
                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                             Iterator 
                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                  it = 
                                                                                                                                                                                                                                                                                            Student_3 s1 =  Student_3(101,"张三",25,"男" Student_3 s2 =  Student_3(102,"马琴","女" Student_3 s3 =  Student_3(103,"赵薇",36,"女" Student_3 s4 =  Student_3(104,"李小梅",31,"女"   Test_3 t =  System.out.println("List集合转Map集合"    System.out.println("\n" System.out.println("Map集合转List集合"     }    

总结

以上是编程之家为你收集整理的java集合(List集合与Map集合的数据转换)全部内容,希望文章能够帮你解决java集合(List集合与Map集合的数据转换)所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!
编程之家官方1群
编程之家官方2群
编程之家官方4群
  • 上一篇:java网络编程(UDP详解)下一篇:java的XML解析(DOM4J技术)

猜你在找的Java相关文章

【实战】利用多线程优化查询百万级数据
前言 日常开发中,难免会遇到需要查询到数据库所有记录的业务场景,在索引完善的情况下,当数据量达到百万级别或者以上的时候,全表查询就需要耗费不少的时间,这时候我们可以从以下几个方向着手优化 优化sql
【设计模式】汉堡中的设计模式——观察者模式
【设计模式】汉堡中的设计模式——观察者模式 情景带入 对于爱吃麦当劳的我来说,自然是不想错过各种动态,可是我又不可能【无时无刻】的蹲在店里等新品吧(还是要搬砖的) 那么有没有一种好的方法,在麦当劳【推
@RequestParam,@RequestBody,@ResponseBody,@PathVariable注解的一点小总结
一、前提知识: http协议规定一次请求对应一次响应,根据不同的请求方式,请求的内容会有所不同; 发送GET请求是没有请求体的,参数会直接拼接保留到url后一并发送; 而POST请求是带有请求体的,带
Java中的重载和重写
关于Java中的重载与重写,每一个java人肯定都学习过,这里就再梳理一遍,加深一下印象,忘记的时候拿出来看一看就好了 重载与重写的区别 重载发生在同一个类里面,同一个方法,拥有不同的参数列表,不同的
每日一记:关于Arrays.asList和Collections.unmodifiableList的一点理解
1、正常创建一个List,对List进行操作 List&lt;Integer&gt; collect = Stream.of(1 ,3 ,5 ,7 ,9).collect(Collectors.toL
Java8——Stream流式操作的一点小总结
我发现,自从我学了Stream流式操作之后,工作中使用到的频率还是挺高的,因为stream配合着lambda表达式或者双冒号(::)使用真的是优雅到了极致!今天就简单分(搬)享(运)一下我对strea
性能优化之数据库篇
性能优化-数据库篇1 首先我们要谈论什么是性能? 吞吐和延迟 没有量化就没有改进 :监控和度量指标可以指导我们从哪里入手 80/20原则:先优化性能瓶颈的地方 过早的优化是万恶之源:选择合适的优化时机
分布式缓存方案
一、从数据说起 我们再做缓存之前需要把数据先分好类 按变化频率: 静态数据:一般不变的,类似于字典表 准静态数据:变化频率很低,部门结构设置,全国行政区划数据 中间状态数据:一些计算的可复用中间数据,
PHPJavaJava SEPythonNumPyC#C&C++RubyVBasp.NetGoPerlnettygRPCDjangoDelphiJsp.NET CoreSpringFlaskSpringbootSpringMVCLuafastadminLaravelMybatisAspGroovyThinkPHPYii
微信公众号搜索 “ 程序精选 ” ,选择关注!
微信公众号搜 "程序精选"关注
  • • 【实战】利用多线程优化查询百
  • • 【设计模式】汉堡中的设计模式
  • • String s1 = new String("
  • • @RequestParam,@RequestBody,
  • • Java中的重载和重写
  • • elasticsearch7.6.1版本+jsoup
  • • 每日一记:关于Arrays.asList和
  • • Java8——Stream流式操作的一点
  • • 加密配置文件里面的敏感数据
  • • 性能优化之数据库篇
  • • 分布式缓存方案
  • • 超详细kafka教程来啦
  • • java-接口和抽象类的联系和区别
  • • java-单例详解
  • • java网络编程(TCP详解)
  • • java网络编程(UDP详解)
  • • java集合(List集合与Map集合的
  • • java的XML解析(DOM4J技术)
  • • 详解java开发环境搭建
  • • 利用JAVA实现DES加密算法
  • • Java基本类型与包装类详细解析
  • • Java打印和打印预览机制实例代
javapythonjQuerylinuxC#AndroiddockerIOSaspUbuntucentosrubyC++asp.net前端perlJSON正则oraclexml表达式VBPostgresqlMVCCASP.NET程序应用lua学习Servervb.netShellSQLite.Netreact配置native是否数据VIMdatabasevueString字符串开发命令笔记运行twitter-bogolang没有vbdjangojenkins类测试为什么c#通过数组模式问题Unix编程连接转换编译项目方法redis启动更改多个function访问加载存储验证之间
联系我们

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>