20161028問(wèn)題解析請(qǐng)點(diǎn)擊今日問(wèn)題下方的“【Java每日一題】20161031”查看(問(wèn)題解析在公眾號(hào)首發(fā),公眾號(hào)ID:weknow619)
package Oct2016;
import java.util.SortedSet;
import java.util.TreeSet;
public class Ques1031 {
public static void main(String[] args) {
SortedSet<People> set = new TreeSet<People>();
set.add(new People(170));
set.add(new People(165));
for(People people : set){
System.out.println("身高:"+people.getHeight());
}
System.out.println();
// 將身高矮的人變高
set.first().setHeight(175); // 之前排在第一位的人就是最矮的
for(People people : set){
System.out.println("身高:"+people.getHeight());
}
}
}
class People implements Comparable<People>{
private int height;
public People(int height) {
super();
this.height = height;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
@Override
public int compareTo(People p) {
// 按身高從矮到高排序
return height - p.height;
}
}
今日問(wèn)題:請(qǐng)問(wèn)主程序輸出結(jié)果是什么?(點(diǎn)擊以下“【Java每日一題】20161031”查看20161028問(wèn)題解析)