博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
equals与==的区分
阅读量:4450 次
发布时间:2019-06-07

本文共 994 字,大约阅读时间需要 3 分钟。

equals与==的区分

对于比较数值

public class Test {public static void main(String[] args){    int a=30;    int b=30;    System.out.println("hellow world!");    System.out.println(a==b);    }}运行结果:hellow world!true

对于比较字符串时,

==比较的是地址,其内容分别保存在了不同的空间,所以即使内容相等,但是地址的值是不相等的。

public class Test {public static void main(String[] args){    String a="hellow";    String b=new String("hellow");    String c=b;    //System.out.println("hellow world!");    System.out.println(a==b);    System.out.println(a==c);    System.out.println(b==c);    }}运行结果:falsefalsetrue

而equals只是比较的是字符串内容而不是地址,但是这里涉及到数据库char和varcha的区别,空格equals是能识别出来的。

public class Test {public static void main(String[] args){    String a="hellow";    String b=new String("hellow");    String c=b;    //System.out.println("hellow world!");    System.out.println(a.equals(b));    System.out.println(a.equals(c));    System.out.println(b.equals(c));    }}运行结果:truetrue    true
  • 更多精彩内容,请关注微信关注公众号 明叶师兄的学堂
    1080293-20190312211630310-32834377.jpg

转载于:https://www.cnblogs.com/renxiuxing/p/8537379.html

你可能感兴趣的文章
zabbix的源码安装
查看>>
磁盘配额中quotacheck不能创建aquota.user和aquota.group文件的问题
查看>>
2014年生日
查看>>
Django Rest Framework-介绍
查看>>
文件夹的创建(cmd利用)
查看>>
福大软工 · 真 · 最终作业
查看>>
2018.08.10 atcoder No Need(线性dp)
查看>>
css3 动画
查看>>
数组转对象
查看>>
扫描目录下的文件并拼接在一起
查看>>
ELK 分布式日志处理 10.12
查看>>
Java虚拟机详解05----垃圾收集器及GC参数
查看>>
7. 单位,移动布局
查看>>
inux中bin与sbin目录的作用及区别介绍
查看>>
USACO 3.1 Contact
查看>>
Office之什么是高内聚低耦合
查看>>
一些奇怪的问题求回答
查看>>
这些年踩过的坑
查看>>
iOS开发拓展篇——如何把项目托管到GitHub
查看>>
性能优化之数据库优化
查看>>