表格是计算机世界最普遍的模型,互联网上看到的所有数据本质上都是“表格”。
ID | 姓名 | 年龄 | 职能 | 入职日期 |
1001 | 小明 | 18 | 讲师 | 2-14 |
1002 | 小红 | 19 | 助教 | 10-10 |
1003 | 小亮 | 20 | 班主任 | 5-5 |
使用二维数组保存表格数据:
import java.util.Arrays;public class Test{public static void main(String[] args){Object[] a1 = {1001,"小明",18,"讲师","2-14"};Object[] a2 = {1002,"小红",19,"助教","10-10"};Object[] a3 = {1003,"小亮",20,"班主任","5-5"};Object[][] emps = new Object[3][];emps[0] = a1;emps[1] = a2;emps[2] = a3;System.out.println(Arrays.toString(emps[0]));System.out.println(Arrays.toString(emps[1]));System.out.println(Arrays.toString(emps[2]));}
}
使用javabean和一维数组保存表格信息:
import java.util.Arrays;public class Test{public static void main(String[] args){Emp[] emps = {new Emp(1001,"小明",18,"讲师","2-14");new Emp(1002,"小红",19,"助教","10-10");new Emp(1003,"小亮",20,"班主任","5-5");};for(Emp e : emps){System.out.println(e);}}
}class Emp{private int id;private String name;private int age;private String job;private String hiredate;public Emp(int id,String name,int age,String job,String hiredate){this.id = id;this.name = name;this.age = age;this.job = job;this.hiredate = hiredate;}@Overridepublic String toString(){return "["+id+","+name+","+age+","+job+","+hiredate+"]";}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 getAge(){return age;}public void setAge(int age){this.age = age;}public String getJob(){return job;}public void setJob(String job){this.job = job;}public String getHiredate(){return hiredate;}public void setHiredate(String hiredate){this.hiredate = hiredate;}
}