文章

27

粉丝

492

获赞

10

访问

255.2k

头像
入门-排序类
备考心情
发布于2021年3月3日 15:07
阅读数 7.9k

P1151

方法1.重写Comparator中的compare方法

o1-o2 升序

o2-o1降序

Collections.sort(student, new Comparator() {

			@Override
			public int compare(Student o1, Student o2) {
				// TODO Auto-generated method stub
				if(order==1)
		            return o1.grade - o2.grade;
		    	else  
		    		return o2.grade - o1.grade;
			}
		});

方法二。重写comparable接口中的compareTo方法

this.compareTo(o)用来比较对象为字符串

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发