==与equal
@ 对象类型比较:(引用类型)
==和equal都表示对象引用的内存地址是否相同
对象类型继承Object并重写方法equal()用于对象的比较
@ 字符串比较:
==表示String引用的内存地址是同一个
equal表示字符串的值相同
===========================================
@String str ="";String str = new String();
表示在内存开辟空间,只是没有往空间放东西,所以这个变量是可以使用的。
@String str = null;
表示存在String的引用,但是没有开辟内存空间,所以不可以在程序中使用。
但是可以用于判断 if(str==null)
Tip:str == null,可以用于释放空间,编译器就会回收。
因此:String字符串的对比,我们一般用equal方法或者if(s1.compare(s2))==0)
【例子】String str = "aa"; String newStr = "bb";这两个对象用==和equal都是为true
String str = new String("aa");String newStr = new String("aa");这两个对象==时为false,但是用equal为true,因为这里分配了两个内存空间
===========================================
str.equal("aa")与"aa".equal(str)区别:
将字符串"aa"写在前面可以避免空指针异常,这是良好的编码规范。
===========================================
@ equal():大小写敏感
@ equalsIgnoreCase():忽略大小写
==与equal的更多相关文章
- [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二
Given a non-empty integer array, find the minimum number of moves required to make all array element ...
- [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等
Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...
- [LeetCode] Partition Equal Subset Sum 相同子集和分割
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
- Equal Sides Of An Array
参考:http://stackoverflow.com/questions/34584416/nested-loops-with-arrays You are going to be given an ...
- Int,Long比较重使用equal替换==
首先,==有很多限制,如Integer 类型的值在[-128,127] 期间,Integer 用 “==”是可以的(参考),超过范围则不行,那么使用equal则代替则完全ok public stati ...
- 无法解决 equal to 操作中 "SQL_Latin1_General_CP1_CI_AS" 和 "Chinese_PRC_CI_AS"
无法解决 equal to 操作中 "SQL_Latin1_General_CP1_CI_AS" 和 "Chinese_PRC_CI_AS" 之间 2011-0 ...
- LeetCode Minimum Moves to Equal Array Elements II
原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ 题目: Given a non-empt ...
- LeetCode Minimum Moves to Equal Array Elements
原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements/ 题目: Given a non-empty i ...
- conflict between "Chinese_PRC_CI_AI" and "Chinese_PRC_CI_AS" in the equal to operation
在SQL SERVICE做关联查询的时候遇到了"conflict between "Chinese_PRC_CI_AI" and "Chinese_PRC_CI ...
- why happen "WaitHandles must be less than or equal to 64"
一.背景: 在一个项目中碰到大数据插入的问题,一次性插入20万条数据(SQL Server),并用200个线程去执行,计算需要花费多少时间,因此需要等200个线程处理完成后,记录花费的时间,需要考虑的 ...
随机推荐
- (转)SimpleDateFormat使用详解
1 SimpleDateFormat 介绍 public class SimpleDateFormat extends DateFormat SimpleDateFormat 是一个以国别敏感的方式格 ...
- java对Microsoft Document的操作--->对Excel的操作
起初,自己想对网站上爬取一些数据来写到Excel表格中,便在网上找了找java操作Excel接口,了解到Apache的POI接口可以对微软的文档进行操作,WIKI搜索的结果如下, HSSF - 提供读 ...
- 基于NFS实现WordPress
实验内容: (1)主机IP nfs server IP :192.168.29.120 nfs server IP: 192.168.29.110 (2)要求 nfs server共享/data/we ...
- hexo博客MathJax公式渲染问题
这个问题自己很早以前便碰到了,用MathJax语法写的一些公式,在本地Markdown编译器上渲染是没问题的,可是部署到hexo博客中就出现问题了,之前我是使用图片代替公式应付过去了,今天从网上找了一 ...
- year:2017 month:08 day:04
2017-08-04 JAVAse 1.final修饰符 final可以修饰类,成员方法,成员变量(static 修饰符不可以修饰类) final的初始化在对象被实例化前即可final 修饰的方法不可 ...
- 详解Tomcat 配置文件server.xml
前言 Tomcat隶属于Apache基金会,是开源的轻量级Web应用服务器,使用非常广泛.server.xml是Tomcat中最重要的配置文件,server.xml的每一个元素都对应了Tomcat中的 ...
- NO.1-M2
一,CSS盒模型 1,当父盒子包裹子盒子,且上边线重合时,给子盒子添加margin-top时,子盒子与父盒子的上边线并不能分开,,而是导致,两个盒子同时下来,而是导致,两个盒子同时下来 使两条上边 ...
- [NOIP模拟赛]约会date LCA(顺便填坑)
这道题也算是厉害了,改了整整俩小时最后发现是深信的LCA打错了,悲伤啊!信仰崩塌了! 顺便复习LCA,给出模板 void init(){//p[i][j]表示i节点2^j的祖先 int j; for( ...
- HTML indexedDB数据库—简单示例
indexedDB数据库的基本概念:在HTML5中,新增一种被称为"indexedDB"的数据库,该数据库是一种存储在客户端本地的NoSQL数据库. <!DOCTYPE ht ...
- 调整ORACLE用户关闭密码有效期
--调整ORACLE用户关闭密码有效期 ----------------------------------2013/11/12 在oracle中执行一下操作:1.查看用户的proifle是那个,一 ...