表格化处理数据1
public class TestMap { public static void main(String[] args){ Map<String,Object> m1=new HashMap<>(); m1.put("姓名","小吴"); m1.put("id","311909011501"); m1.put("毕业时间","2022.8.1"); Map<String,Object> m2=new HashMap<>(); m2.put("姓名","小赵"); m2.put("id","311909011503"); m2.put("毕业时间","2021.8.1"); List<Map<String,Object>> list=new ArrayList<>(); list.add(m1); list.add(m2); for(Map<String ,Object> row:list){ Set<String>key=row.keySet(); for(String K:key){ System.out.print(K+":"+row.get(K)+" "); } System.out.println(); } } }表格化处理数据2
import java.util.*; public class Test2 { public static void main(String[] args){ Person p1=new Person("小吴",12); Person p2=new Person("小赵",18); List <Person>list=new ArrayList<>(); list.add(p1); list.add(p2); for(Person p:list){ System.out.println(p);//不要忘了重写toString方法 } //法三 Map<Integer,Person>map=new HashMap<>(); map.put(1,p1); map.put(2,p2); Set<Integer>key=map.keySet(); for(Integer K:key){ System.out.println(map.get(K)); } } }