当前位置:网站首页>Comparator summary
Comparator summary
2022-06-12 13:45:00 【Disobey the law】
Comparator summary
1. Internal comparator
public class ClassName implements Comparable<Object>{
public ClassName{
}
public int compareTo(Object o){
return this.-o.;// Ascending
}
}
Collections.sort(array);
2. External comparator
public class MyComparator implements Comparator<Object>{
public int compare(Object first,Object second){
return first.-second.;// Ascending
//String Type is used (first.).compareTo(second.)
}
}
Collections.sort(array,new MyComparator());
3. Anonymous inner class
Collections.sort(array,new Comparator<Object>{
public int compare(Object first,Object second){
return first.-second.;
}
});
4.Lambda
Collections.sort(array,(first,second)->{
return frist.-second.
});
边栏推荐
猜你喜欢

关于#SQLite写注册功能时,数据表查询出错#的问题,如何解决?

一种快速创建测试窗口的方法

xcode 调试openGLES

Xcode debugging OpenGLES

数据类型转换和条件控制语句

Pytorch framework

Innovation training (XI) summary of some bugs in the development process

Relevant knowledge points of cocoapods

Codeforces 1629 F2. Game on sum (hard version) - Yang Hui's triangle, violence, finding rules
Introduction to color coding format
随机推荐
import torch_ Data view of geometric
xcode 调试openGLES
苹果电脑上MySQL安装完成找不到怎么办
Qualcomm platform development series (Protocol) QMI brief introduction and usage
Transmission and response of events and use cases
Explanation of static and extern keywords
2061: [example 1.2] trapezoidal area
What if the MySQL installation on the apple computer is completed and cannot be found
Scyther工具形式化分析Woo-Lam协议
RK3399平台开发系列讲解(内核调试篇)2.50、systrace的使用
Script import CDN link prompt net:: err_ FILE_ NOT_ Found problem
go-zero 微服务实战系列(二、服务拆分)
view的子视图的递归
Octopus network progress monthly report | may 1-May 31, 2022
Pytorch framework
Factory mode of "object creation" mode
Implementing pytorch style deep learning framework similartorch with numpy
Hash tables, sets, maps, trees, heaps, and graphs
Behind the unsealing of Shanghai, this group of developers "cloud gathering" built an AI anti epidemic robot
Debug code to quickly locate the error location