当前位置:网站首页>Using containers to store table data
Using containers to store table data
2020-11-08 21:08:00 【8Years】
Method 1. The data used for storing rows is map. There will be more map In the list Inside .( The container can hold anything )
public class TestStoreData {
public static void main(String[] args) {
Map<String,Object> row1=new HashMap<>();
row1.put("id",1001);
row1.put(" full name "," Zhang San ");
row1.put(" salary ",200);
row1.put(" Date of entry ","2009");
Map<String,Object> row2=new HashMap<>();
row2.put("id",1002);
row2.put(" full name "," Zhao si ");
row2.put(" salary ",50);
row2.put(" Date of entry ","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();
}
}
}
Output results
Name Zhang San salary 200 id1001 Date of entry 2009
Name: Zhao Si salary 50 id1002 Date of entry 2010
Method 2: Use Javabean and list Store the entire table
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;
}
}
Be careful :JavaBean Want to have 1.getter,setter Method 2. Constructors .3. Parameterless constructors , And there are toString Method
版权声明
本文为[8Years]所创,转载请带上原文链接,感谢
边栏推荐
- 云计算之路-出海记-小目标:Hello World from .NET 5.0 on AWS
- 快来看看!AQS 和 CountDownLatch 有怎么样的关系?
- Introduction and application of swagger
- [200 interview experience], programmer interview, common interview questions analysis
- 给大家介绍下,这是我的流程图软件 —— draw.io
- CountDownLatch 瞬间炸裂!同基于 AQS,凭什么 CyclicBarrier 可以这么秀?
- Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19
- 寻找性能更优秀的动态 Getter 和 Setter 方案
- Leetcode 45 jumping game II
- Queue with two stacks
猜你喜欢
Iterm2 configuration and beautification
Flink系列(0)——准备篇(流处理基础)
Five phases of API life cycle
云计算之路-出海记-小目标:Hello World from .NET 5.0 on AWS
后缀表达式转中缀表达式
Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19
Solve the failure of go get download package
AI人工智能编程培训学什么课程?
移动大数据自有网站精准营销精准获客
Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
随机推荐
Part I - Chapter 1 Overview
第一部分——第1章概述
Tasks of the first week of information security curriculum design (analysis of 7 instructions)
Python的特性与搭建环境
CMS垃圾收集器
大数据软件学习入门技巧
Mycat搭建
单例模式的五种设计方案
动态规划设计:最大子数组
EntityFramework Core上下文实例池原理分析
Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020
Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
Creating a text cloud or label cloud in Python
PAT_ Grade A_ 1056 Mice and Rice
寻找性能更优秀的动态 Getter 和 Setter 方案
文件拷贝的实现
【200人面试经验】,程序员面试,常见面试题解析
Five phases of API life cycle
经典动态规划:最长公共子序列
Newbe.ObjectVisitor 样例 1