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<>