当前位置:网站首页>使用容器存储表格数据
使用容器存储表格数据
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
边栏推荐
- RSA asymmetric encryption algorithm
- 解决IE、firefox浏览器下JS的new Date()的值为Invalid Date、NaN-NaN的问题
- 计算机网络 应用层
- Iterm2 configuration and beautification
- Part I - Chapter 1 Overview
- CountDownLatch 瞬间炸裂!同基于 AQS,凭什么 CyclicBarrier 可以这么秀?
- 【Elasticsearch 技术分享】—— 十张图带大家看懂 ES 原理 !明白为什么说:ES 是准实时的!
- 解决go get下载包失败问题
- To introduce to you, this is my flow chart software—— draw.io
- Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020
猜你喜欢
Swagger介绍和应用
装饰器(二)
APReLU:跨界应用,用于机器故障检测的自适应ReLU | IEEE TIE 2020
文件拷贝的实现
Come and have a look! What is the relationship between AQS and countdownlatch?
MongoDB数据库
Suffix expression to infix expression
【云服务】阿里云服务器ECS实例规格那么多,如何选型?最佳实践说明
新手入坑指南:工作原因“重启”Deepin系统,发现真的香啊
abp(net core)+easyui+efcore实现仓储管理系统——出库管理之五(五十四)
随机推荐
RSA asymmetric encryption algorithm
go语言参数传递到底是传值还是传引用?
Decorator (2)
Case analysis of entitycore framework
Constructors and prototypes
Summary of interface test case ideas
单例模式的五种设计方案
Regular backup of WordPress website program and database to qiniu cloud
Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
Chapter five
C / C + + knowledge sharing: function pointer and pointer function, can you understand after reading this article?
VirtualBox install centos7
计算机网络 应用层
npm install 无响应解决方案
Looking for better dynamic getter and setter solutions
Dynamic query processing method of stored procedure
Solve the problem that the value of new date() of JS in IE and Firefox is invalid date and Nan Nan
EntityFramework Core上下文实例池原理分析
用两个栈实现队列
JVM真香系列:轻松理解class文件到虚拟机(下)