• java--双列集合嵌套


    package com.test;
    import com.bean.*;

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collection;
    import com.bean.Student;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Comparator;
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.LinkedHashMap;
    import java.util.LinkedHashSet;
    import java.util.List;
    import java.util.Map;
    import java.util.Random;
    import java.util.Scanner;
    import java.util.Set;
    import java.util.TreeMap;
    import java.util.TreeSet;

    import com.bean.Student;
    public class test {

    //@SuppressWarnings({ "rawtypes", "unchecked" })
    
    
    
    public static  void main(String[] args) {
    

    // extracted_52();
    HashMap<teacher,String> hm =new HashMap<>();
    hm.put(new teacher("zhangsan", 23), "beijing");
    hm.put(new teacher("lige", 26), "shanghai");
    hm.put(new teacher("wangwu", 25), "guangzhou");
    System.out.println(hm);
    HashMap<teacher,String> h1m =new HashMap<>();
    h1m.put(new teacher("huang", 24), "beijing");
    h1m.put(new teacher("zhang", 26), "shanghai");
    h1m.put(new teacher("wang", 25), "guangzhou");
    System.out.println(h1m);
    HashMap<HashMap<teacher,String>,String> hm1= new HashMap<>();
    hm1.put(hm,"88");
    hm1.put(h1m,"99");
    for(HashMap<teacher,String> h:hm1.keySet() ) {
    String value =hm1.get(h);
    for(teacher key: h.keySet()) { //获取所有的学生
    String value2 =h.get(key);
    System.out.println(key+"="+value2+"="+value);
    }
    }
    }

    package com.test;

    public class teacher implements Comparable {
    private String name;
    private int age;
    public teacher(String name, int age) {
    super();
    this.name = name;
    this.age = age;
    }
    public teacher() {
    super();
    // TODO Auto-generated constructor stub
    }
    @Override
    public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + age;
    result = prime * result + ((name == null) ? 0 : name.hashCode());
    return result;
    }
    @Override
    public boolean equals(Object obj) {
    if (this == obj)
    return true;
    if (obj == null)
    return false;
    if (getClass() != obj.getClass())
    return false;
    teacher other = (teacher) obj;
    if (age != other.age)
    return false;
    if (name == null) {
    if (other.name != null)
    return false;
    } else if (!name.equals(other.name))
    return false;
    return true;
    }
    @Override
    public String toString() {
    return "teacher [name=" + name + ", age=" + age + "]";
    }
    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;
    }
    @Override
    public int compareTo(teacher arg0) {
    // TODO Auto-generated method stub
    int num =this.age-arg0.age;
    return num==0?this.name.compareTo(arg0.name):num;
    }
    }

    ******************************人因为有理想、梦想而变得伟大,而真正伟大就是不断努力实现理想、梦想*****************************
  • 相关阅读:
    Oracle报错:ORA-01747: user.table.column, table.column 或列说明无效
    easyUI 比较时间大小
    五个在XML文档中预定义好的实体
    js截取字符串
    luogu2155 [SDOI2008]沙拉公主的困惑
    Codeforces Round #533 (Div. 2)题解
    luogu3327 [SDOI2015]约数个数和
    luogu3911 最小公倍数之和(莫比乌斯反演)
    luogu4449 于神之怒加强版(莫比乌斯反演)
    luogu3704 [SDOI2017]数字表格(莫比乌斯反演)
  • 原文地址:https://www.cnblogs.com/cloudLi/p/13050263.html
Copyright © 2020-2023  润新知