赛德勤
约 986 字大约 3 分钟
2026-04-04
为什么要重写hashcode
hashcode默认计算对象的hashcode,如果两个对象地址不同,内容相同。计算的两个hash值是不同
的,为了避免这种情况需要重写hashcode
equals默认也是对象的引用地址,重写后比较对象的值 所以,我们一般会在使用hashmap存储数据时,让equals和hashcode的值保持一致
ArrayList在什么情况下比LinkedList插入快


中间位置插入 arraylist > linkedlist 差距明显 10(稳定)
- 真正耗时的操作System.arraycopy(elementData, index, elementData, index + 1, size - index);
插入位置的选取对LinkedList有很大的影响,一直往数据中间部分插入删除的时候,ArrayList比LinkedList更快原因大概就是当数据量大的时候,system.arraycopy的效率要比每次插入LinkedList都需要从端查找index和分配节点node来的更快
数据库索引是什么
一种用于快速查询和检索数据的数据结构 常见的索引结构有: B 树, B+树和 Hash。
优点 :
- 使用索引可以大大加快 数据的检索速度(大大减少检索的数据量), 这也是创建索引的最主要的原因。
- 通过创建唯一性索引,可以保证数据库表中每一行数据的唯一性。
缺点 :
- 创建索引和维护索引需要耗费许多时间。当对表中的数据进行增删改的时候,如果数据有索引,那么索引也需要动态的修改,会降低 SQL 执行效率。
- 索引需要使用物理文件存储,也会耗费一定空间。

自定义对象多条件排序
继承comparable接口 实现compareTo(
<E>o)方法匿名内部类实现compartor接口,实现compare(
<E>o1,<E>o2)方法
public class Student implements Comparable<Student> {
private String name;
private Integer age;
private Double mathScore;
private Double englishScore;
@Override
public boolean equals(Object o) {
//如果是同一个对象返回true,反之返回false
if (this == o) return true;
//判断是否类型相同
if (o == null || getClass() != o.getClass()) return false;
Student student = (Student) o;
return Objects.equals(name, student.name) &&
Objects.equals(age, student.age) &&
Objects.equals(mathScore, student.mathScore) &&
Objects.equals(englishScore, student.englishScore);
}
@Override
public int hashCode() {
return Objects.hash(name, age, mathScore, englishScore);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Double getMathScore() {
return mathScore;
}
public void setMathScore(Double mathScore) {
this.mathScore = mathScore;
}
public Double getEnglishScore() {
return englishScore;
}
public void setEnglishScore(Double englishScore) {
this.englishScore = englishScore;
}
public Student() {
}
public Student(String name, Integer age, Double mathScore, Double englishScore) {
this.name = name;
this.age = age;
this.mathScore = mathScore;
this.englishScore = englishScore;
}
/*
* description: 自定义比较,先比较数学成绩,再比较英语成绩,再比较年龄
* @Param: [s]
* @Return: int
**/
@Override
public int compareTo(Student s) {
if(!mathScore.equals(s.mathScore)){
return -(int) (mathScore-s.mathScore);
}else if(!englishScore.equals(s.englishScore)){
return -(int)(englishScore-s.englishScore);
}else {
return s.age-age;
}
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
", mathScore=" + mathScore +
", englishScore=" + englishScore +
'}';
}
}public static void main(String[] args) {
Student stu1 = new Student("胡梓卓1", 22, 89.5, 88.6);
Student stu2 = new Student("胡梓卓2", 22, 68.0, 16.0);
Student stu3 = new Student("胡梓卓3", 21, 68.0, 25.0);
List<Student> list = new ArrayList<>();
list.add(stu1);
list.add(stu2);
list.add(stu3);
Collections.sort(list,(student1,student2)->{
if(!student1.getMathScore().equals(student2.getMathScore())){
return (int) (student2.getMathScore()-student1.getMathScore());
}else if(!student1.getEnglishScore().equals(student2.getEnglishScore())){
return (int)(student2.getEnglishScore()-student1.getEnglishScore());
}else {
return student2.getAge()-student1.getAge();
}
});
list.forEach(System.out ::println);
}public class EpvModuleSampleDto implements Comparable<EpvModuleSampleDto>{
/**
* 序号
*/
@PropertyDesc(desc = "序号")
private Integer srl;
public Integer getSrl(){return srl;}
public void setSrl(Integer srl){this.srl = srl;}
@Override
public int compareTo(EpvModuleSampleDto o) {
if (o.getSrl() == null) {
return 0;
}
return srl.compareTo(o.getSrl());
}
}
Collections.sort(list);git命令
上传冲突怎么解决
暂存区作用
那么你什么时候去选择要提交哪些文件呢?Commit操作是将暂存区的内容全部提交,所以我们要回到暂存区中思考;从工作区到暂存区,使用Git Add 文件名,我们可以选择性地向暂存区添加内容,然后将其分批提交,暂存区的意义是它将你准备提交的内容分批整体处理
贡献者
更新日志
2026/4/5 03:39
查看所有更新日志
fb8bc-更新为vuepress于