Java代码规范equals, for continue
代码规范equals, for continue
代码规范1 if(v.getPartner().contains("文案")){ } //修改成: if("文案".equals(v.getPartner())){ } //避免因为数据原因导致v.getPartner()为null的情况,然后再调用contains方法导致报空指针异常。
代码规范2 for (Vo vo : ListVo) { if(判断条件是否如何条件){ //return; continue; } } //for循环中的使用return提前退出了,而应该使用continue关键字。避免for循环中的数据不会全部执行到。
代码语言:javascript代码运行次数:0运行复制/**
* 打印输出:
* id不等于8(字符串与Integer)
* id等于8(字符串与字符串)
* id等于8(Integer与Integer)
*/
public class IntegerTest {
public static void main(String[] args) {
Integer id = 8;
if("8".equals(id)){
System.out.println("id等于8(字符串与Integer)");
}else {
System.out.println("id不等于8(字符串与Integer)");
}
if("8".equals(String.valueOf(id))){
System.out.println("id等于8(字符串与字符串)");
}else {
System.out.println("id不等于8(字符串与字符串)");
}
//如果Integer id = null; 报:Exception in thread "main" java.lang.NullPointerException
if(8 == id){
System.out.println("id等于8(Integer与Integer)");
}else {
System.out.println("id不等于8(Integer与Integer)");
}
}
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2022-08-05,如有侵权请联系 cloudcommunity@tencent 删除javaequals代码规范数据字符串发布者:admin,转转请注明出处:http://www.yc00.com/web/1754984050a5224057.html
评论列表(0条)