java将对象数组作为Map的key值,对数据进行增删改查

java将对象数组作为Map的key值,对数据进行增删改查
源文件Student.java
import java.util.Map;
import java.util.Scanner;

public class Student implements Comparable<Student>
{
   
	int id;
	String name;
	String sex;
	int age;
	double score;
	public Student()
	{
   		
	}
	public Student(int id, String name, String sex, int age, double score) {
   
		super();
		this.id = id;
		this.name = name;
		this.sex = sex;
		this.age = age;
		this.score = score;
	}
	@Override
	public String toString() 
	{
   
		return "id:" + id + ", 姓名:" + name + ", 性别:" + sex + ", 年龄:" + age + ", 分数:" + score;
	}
	public static void initial(Map<Student,String> map)
	{
   
		/*
		Student stu1=new Student(3,"小杰","男",25,99.0);
		Student stu2=new Student(5,"小孙","女",25,90.0);
		Student stu3=new Student(2,"老王","男",26,66.0);
		Student stu4=new Student(1,"大毛","女",24,88.0);
		map.put(stu1, "A");
		map.put(stu2, "B");
		map.put(stu3, "C");
		map.put(stu4, "D");
		*/
		map.put(new Student(30,"小杰","男",25,99.0),"A");
		map.put(new Student(40,"小孙","女",25,90.0),"B");
		map.put(new Student(20,"老王","男",26,66.0),"C");
		map.put(new Student(10,"大毛","女"
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值