==和equals
1.== 在比较基本数据类型时,判断两个变量的值是否相等
== 在比较引用类型时,比较的是引用类型的内存地址
2.euqals是超类object下的方法,只能比较引用类型,不能比较基本类型。其在object中定义的功能和==是相同的,都是比较变量内存地址是否相同
而在stirng类,integer类中,equals方法被重新,比较的是两者的值是否相同
如果自建类,不重写euqals方法的话,则自建类的equals方法比较的是内存地址是否相同
3.String a = “123” ;
String b = “123”;
String c = new String(“123”);
其中a和b的内存地址相同,a和c的内存地址不同
比较以下两段代码
public static String dicUidCreator(int section, int subject, List<SidKnowledge> knowIds) {
try {
int mainKnowledge = knowIds.stream().filter(x -> x.getKnowRank() == 1).findFirst().get().getKnowId();
knowIds.removeIf(x -> x.getKnowId().intValue() == mainKnowledge);
String result = String.format("%d%02d-%d", section, subject, mainKnowledge);
result = knowIds.size() > 0
? String.format("%s-%s", result, StringUtils
.join(knowIds.stream().map(x -> x.getKnowId()).sorted().collect(Collectors.toList()), '-'))
: result;
return result;
} catch (NoSuchElementException e) {
System.err.println("没有主要知识点");
}
return null;
}
public static String getUid(Integer section,Integer subject,List<KnowInfo> knowInfo){
KnowInfo first = knowInfo.stream().filter(x->x.getKnow_rank().equals("1")).findFirst().get();
knowInfo.removeIf(x->x.getKnow_rank().equals("1"));
String uid = String.format("%d%02d-%s", section, subject, first.getKnow_id());
if(knowInfo.size()>0)
uid =String.format("%s-%s", uid,StringUtils.join(knowInfo.stream().map(x->x.getKnow_id()).sorted().collect(Collectors.toList()), '-'));
return uid;
}