当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Why need to use API management platform
- CMS garbage collector
- An online accident caused by improper use of thread pool
- Come and have a look! What is the relationship between AQS and countdownlatch?
- Proficient in high concurrency and multithreading, but can't use ThreadLocal?
- npm install 无响应解决方案
- The minimum insertion times of palindrome
- Dynamic planning
- Five design schemes of singleton mode
- Introduction and application of swagger
猜你喜欢
Five factors to consider before choosing API management platform
Test comparison of three domestic cloud databases
Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19
第五章
国内三大云数据库测试对比
Flink系列(0)——准备篇(流处理基础)
The interface testing tool eolinker makes post request
装饰器(一)
快来看看!AQS 和 CountDownLatch 有怎么样的关系?
Newbe.ObjectVisitor Example 1
随机推荐
RSA asymmetric encryption algorithm
JVM Zhenxiang series: easy understanding of class files to virtual machines (Part 2)
npm install 无响应解决方案
Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?
寻找性能更优秀的不可变小字典
go语言参数传递到底是传值还是传引用?
JVM真香系列:轻松理解class文件到虚拟机(下)
APReLU:跨界应用,用于机器故障检测的自适应ReLU | IEEE TIE 2020
Suffix expression to infix expression
数组初相识
使用Fastai开发和部署图像分类器应用
Looking for a small immutable dictionary with better performance
接口测试用例思路总结
Leetcode 45 jumping game II
Using annotation + interceptor to implement asynchronous execution
Summary of interface test case ideas
PAT_ Grade A_ 1056 Mice and Rice
Development and deployment of image classifier application with fastai
使用基于GAN的过采样技术提高非平衡COVID-19死亡率预测的模型准确性
Array acquaintance