龙空技术网

如何在Java中使用List

dirac 100

前言:

而今你们对“listtjava”大体比较讲究,各位老铁们都想要知道一些“listtjava”的相关资讯。那么小编也在网上网罗了一些有关“listtjava””的相关文章,希望你们能喜欢,各位老铁们一起来了解一下吧!

import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;public class Main {    public static void main(String[] args) {        int[] ids = {111, 112, 113, 114, 115, 116};        String[] names = {"张三", "李四", "王五", "马六", "阮七", "刘八"};        String[] genders = {"男", "女", "男", "女", "男", "女"};        //存放所有学生信息        List<Map<String, Object>> students = new ArrayList<>();        for (int i = 0; i < ids.length; i++) {            Map<String, Object> stu = new HashMap<String, Object>();            stu.put("id", ids[i]);            stu.put("name", names[i]);            stu.put("gender", genders[i]);            students.add(stu);        }        System.out.println("学号\t\t姓名\t\t性别");        //得到所有学生信息        for (Map<String, Object> stu : students)            System.out.println(stu.get("id").toString() + "\t\t" + stu.get("name") + "\t\t" + stu.get("gender"));    }}

标签: #listtjava