admin管理员组文章数量:1487745
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代码规范数据字符串本文标签: Java代码规范equalsfor continue
版权声明:本文标题:Java代码规范equals, for continue 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/shuma/1754984065a3182084.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论