1、S02E112_01容器存储数据综合练习_javabean的介绍
一个类对应一个表结构
一个对象对应一条记录
package com.test.employee;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Employee {//Javabean,实体类,一个类对应一个表结构
private int id;
private String name;
private int salary;
private String department;
private Date hireDate;
public Employee(int id, String name, int salary, String department,
String hireDate) {
super();
this.id = id;
this.name = name;
this.salary = salary;
this.department = department;
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
try {
this.hireDate = dateFormat.parse(hireDate);
} catch (ParseException e) {
e.printStackTrace();
}
}
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 int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public Date getHireDate() {
return hireDate;
}
public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}
}
/////////////////////////////////////
package com.test.employee;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
//一个对象对应一条记录
Employee employee1 = new Employee(0301, "高", 3000, "项目部", "2007-10");
Employee employee2 = new Employee(0302, "马", 3000, "教学部", "2006-10");
Employee employee3 = new Employee(0303, "裴", 3000, "教学部", "2007-10");
List<Employee> list = new ArrayList<Employee>();
list.add(employee1);
list.add(employee2);
list.add(employee3);
printName(list);
}
public static void printName(List<Employee> list){
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).getName());
}
}
}
2、S02E113_01容器存储数据综合练习_Map保存表记录
一个Map对象对应一条记录!
package com.test.employee;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MapStoreData {
public static void main(String[] args) {
//一个Map对象对应一条记录!
Map map1 = new HashMap();
map1.put("id", 0301);
map1.put("name", "高");
map1.put("salary", 3000);
map1.put("department", "项目部");
map1.put("hireDate", "2007-10");
Map map2 = new HashMap();
map2.put("id", 0302);
map2.put("name", "马");
map2.put("salary", 3000);
map2.put("department", "教学部");
map2.put("hireDate", "2006-10");
Map map3 = new HashMap();
map3.put("id", 0303);
map3.put("name", "裴");
map3.put("salary", 3000);
map3.put("department", "教学部");
map3.put("hireDate", "2007-10");
List<Map> list = new ArrayList<Map>();
list.add(map1);
list.add(map2);
list.add(map3);
printName(list);
}
public static void printName(List<Map> list){
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).get("name") + "--" + list.get(i).get("salary"));
}
}
}
3、S02E114_01容器_迭代器遍历List及Set和List迭代器源码分析
(1)List迭代器部分源码
public boolean hasNext() {
return cursor != size();//初始值cursor = 0
}
public E next() {
checkForComodification();
try {
int i = cursor;
E next = get(i);
lastRet = i;
cursor = i + 1;
return next;
} catch (IndexOutOfBoundsException e) {
checkForComodification();
throw new NoSuchElementException();
}
}
public void remove() {
if (lastRet < 0)
throw new IllegalStateException();
checkForComodification();
try {
AbstractList.this.remove(lastRet);
if (lastRet < cursor)
cursor--;
lastRet = -1;
expectedModCount = modCount;
} catch (IndexOutOfBoundsException e) {
throw new ConcurrentModificationException();
}
}
(2)Set迭代器部分源码:以后研究
4、S02E115_01容器_迭代器遍历Map的两种方式
视频是114的,只能参考网上资源:
http://blog.csdn.net/sofokiller/article/details/8532084