当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 在Python中创建文字云或标签云
- Copy the picture
- JVM真香系列:轻松理解class文件到虚拟机(上)
- 存储过程动态查询处理方法
- JVM Zhenxiang series: easy understanding of class files to virtual machines (Part 2)
- Realization of file copy
- Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020
- 使用基于GAN的过采样技术提高非平衡COVID-19死亡率预测的模型准确性
- CMS垃圾收集器
- 第五章
猜你喜欢

Octave basic syntax

Iptables from introduction to mastery

Mycat搭建

Classical dynamic programming: longest common subsequence

第五章

Is parameter passing in go language transfer value or reference?

国内三大云数据库测试对比

Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?

Aprelu: cross border application, adaptive relu | IEEE tie 2020 for machine fault detection

Django之简易用户系统(3)
随机推荐
Solve the failure of go get download package
给大家介绍下,这是我的流程图软件 —— draw.io
进程 线程 协程
APReLU:跨界应用,用于机器故障检测的自适应ReLU | IEEE TIE 2020
存储过程动态查询处理方法
Fiddler无法正常抓取谷歌等浏览器的请求_解决方案
简明 VIM 练级攻略
数组初相识
Dynamic planning
Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?
Come and have a look! What is the relationship between AQS and countdownlatch?
Octave basic syntax
Decorator (2)
npm install 无响应解决方案
LeetCode 45 跳跃游戏II
Django's simple user system (3)
The road of cloud computing - going to sea - small goal: Hello world from. Net 5.0 on AWS
Swagger介绍和应用
Is parameter passing in go language transfer value or reference?
【200人面试经验】,程序员面试,常见面试题解析