- 1、本文档共4页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
equals( )方法与 == 运算符的用法比较((equals) compared with the operator = =.)
equals( )方法与 == 运算符的用法比较((equals) compared with the operator = =.)
Some readers will on when to use equal operator = = and when to use the equals () method are confused, this confusion is mainly equals (...) and = = operator confusion. Although the results are sometimes the same, however, their usage is different. Take a look at the following example:
Public class StringExample
{
Public, static, void, main (String, args[])
{
String S0 = Programming;
String S1 = new String (Programming);
String S2 = Program + Ming;
System.out.println (s0.equals (S1): + (s0.equals (S1));
System.out.println (s0.equals (S2): + (s0.equals (S2));
System.out.println (S0 = = s1: + (S0 = = S1));
System.out.println (S0 = = s2: + (S0 = = S2));
}
}
This example contains 3 variables of type String, two of which were assigned to a constant expression Programming is another assignment to a new value for an instance of the Programming of the String class, the use of equals (...) and = =
Operators compare and produce the following results:
S0.equals (S1): true
S0.equals (S2): true
S0 = s1: false
S0 = s2: true
The String.equals () method compares the content of the string, and uses the equals (...) method to compare all characters in the string one by one. If it is exactly equal, then return the true. In this case, all strings are the same, so when the string S0 is compared to S1 or S2, we get the return value of true. Operator = = is a reference to the String instance, in this case it is obvious that S0 and S1 are not the same instance of String. But S0 and S2 are the same. Maybe youll ask S0 and S2 how they are the same object? The answer to this question comes from the chapter on string constants String Literals in the Java language specification. In this example, Programming, Program and Ming are string constants. They are determined at compile time. When a string is connected by multiple string constants, such as S2, it is also determined to be a string constant at compile time. Java ensures tha
您可能关注的文档
- 英国留学 本科申请留学的五种途径(Five ways of applying for study abroad in UK).doc
- 考驾照容易丢分的点(Driving license is easy to lose points).doc
- 耳针疗法(Auriculotherapy).doc
- 英国留学 申请拒绝率居高不下的名校汇总(British universities to apply for refusal rates remain high school summary).doc
- 英国留学 申请留学家长最关心的热点问题解答(The hot issues for parents studying in the UK).doc
- 英国留学 过来人分享申请剑桥大学的申请经验(British students studying abroad share applications for University of Cambridge).doc
- 英文名大全【女子】(English name Daquan [women]).doc
- 英国皇室婚礼(Royal Wedding).doc
- 考试,其他考试(Examinations, other examinations).doc
- 英国留学2012年十大会计金融专业名校的录取要求(Study in Britain in 2012 the ten major accounting and financial professional schools admission requirements).doc
- 物流运输行业离职证明(8篇).docx
- 天津渤海职业技术学院单招数学高频难、易错点题附完整答案详解(夺冠).docx
- 城住房建设规划编制导则53页_图文.docx
- 天津渤海职业技术学院单招数学经典例题附完整答案详解【全优】.docx
- 天津滨海职业学院单招数学考试综合练习【必刷】附答案详解.docx
- 天津电子信息职业技术学院单招数学考前冲刺练习含答案详解(达标题).docx
- 高血压药品治疗.pptx
- 《语文课本:《子夜》现代诗歌鉴赏与赏析教案》.doc
- 天津理工大学中环信息学院单招数学题库检测试题打印及完整答案详解【名校卷】.docx
- 宁夏工业职业学院单招数学能力检测试卷【培优A卷】附答案详解.docx
文档评论(0)