当前位置:网站首页>使用容器存储表格数据
使用容器存储表格数据
2020-11-08 21:08:00 【8Years】
方法1.存储行的数据使用map。再将多个map放进list里面。(容器可以放任何东西)
public class TestStoreData {
public static void main(String[] args) {
Map<String,Object> row1=new HashMap<>();
row1.put("id",1001);
row1.put("姓名","张三");
row1.put("薪水",200);
row1.put("入职日期","2009");
Map<String,Object> row2=new HashMap<>();
row2.put("id",1002);
row2.put("姓名","赵四");
row2.put("薪水",50);
row2.put("入职日期","2010");
List<Map<String,Object>> table=new ArrayList<>();
table.add(row1);
table.add(row2);
for (Map<String,Object> row:table) {
Set<String> keyset=row.keySet();
for (String key:keyset) {
System.out.print(key+row.get(key)+" ");
}
System.out.println();
}
}
}
输出结果
姓名张三 薪水200 id1001 入职日期2009
姓名赵四 薪水50 id1002 入职日期2010
方法2:使用Javabean和list存储整张表格
public class TestStoreDatatwo {
public static void main(String[] args) {
Stu stu1=new Stu(1,"li",100.0);
Stu stu2=new Stu(2,"li",100.0);
List<Stu> list=new ArrayList<>();
list.add(stu1);
list.add(stu2);
for (Stu stu:list) {
System.out.println(stu);
}
}
}
class Stu {
int id;
String name;
Double salary;
public Stu() {
}
public Stu(int id, String name, Double salary) {
this.id = id;
this.name = name;
this.salary = salary;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getSalary() {
return salary;
}
public void setSalary(Double salary) {
this.salary = salary;
}
@Override
public String toString() {
return "id:" + id + ",name:" + name + ",salary:" + salary;
}
}
注意:JavaBean要有 1.getter,setter方法 2.构造器。3.无参构造器,还有有toString方法
版权声明
本文为[8Years]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4583813/blog/4707215
边栏推荐
- Dynamic programming: maximum subarray
- Dynamic planning
- 装饰器(一)
- Dynamic query processing method of stored procedure
- Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020
- JVM真香系列:轻松理解class文件到虚拟机(下)
- Newbe.ObjectVisitor Example 1
- 都说程序员钱多空少,程序员真的忙到没时间回信息了吗?
- git操作与分支管理规范
- 存储过程动态查询处理方法
猜你喜欢
给大家介绍下,这是我的流程图软件 —— draw.io
第一部分——第1章概述
go语言参数传递到底是传值还是传引用?
Iterm2 configuration and beautification
新手入坑指南:工作原因“重启”Deepin系统,发现真的香啊
The interface testing tool eolinker makes post request
To introduce to you, this is my flow chart software—— draw.io
Part I - Chapter 1 Overview
[elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!
APReLU:跨界应用,用于机器故障检测的自适应ReLU | IEEE TIE 2020
随机推荐
Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
解决IE、firefox浏览器下JS的new Date()的值为Invalid Date、NaN-NaN的问题
Process thread coroutine
Tasks of the first week of information security curriculum design (analysis of 7 instructions)
使用基于GAN的过采样技术提高非平衡COVID-19死亡率预测的模型准确性
Five factors to consider before choosing API management platform
Django之简易用户系统(3)
Case analysis of entitycore framework
Five design schemes of singleton mode
API生命周期的5个阶段
C/C++学习日记:原码、反码和补码
MYCAT build
The minimum insertion times of palindrome
LeetCode 45 跳跃游戏II
[cloud service] there are so many ECS instances on alicloud server, how to select the type? Best practice note
Learn volatile, you change your mind, I see
net.sf.json . jsonobject's format processing of time stamp
动态规划设计:最大子数组
Flink系列(0)——准备篇(流处理基础)
Leetcode 45 jumping game II