补充关于equals的比较方式

补充(equals比较)

java.lang.String类中的方法

equals判断相等依据

策略:如果与目标相等返回0,小于目标返回值小于0,大于目标返回值大于0

1@Native static final byte LATIN1 = 0; 2@Native static final byte UTF16 = 1;
1 /** 2 * Compares this string to the specified object. The result is {@code 3 * true} if and only if the argument is not {@code null} and is a {@code 4 * String} object that represents the same sequence of characters as this 5 * object. 6 * 7 * <p>For finer-grained String comparison, refer to 8 * {@link java.text.Collator}. 9 * 10 * @param anObject 11 * The object to compare this {@code String} against 12 * 13 * @return {@code true} if the given object represents a {@code String} 14 * equivalent to this string, {@code false} otherwise 15 * 16 * @see #compareTo(String) 17 * @see #equalsIgnoreCase(String) 18 */ 19public boolean equals(Object anObject) { 20 if (this == anObject) { 21 return true; 22 } 23 if (anObject instanceof String) { 24 String aString = (String)anObject; 25 if (coder() == aString.coder()) { 26 return isLatin1() ? StringLatin1.equals(value, aString.value) 27 : StringUTF16.equals(value, aString.value); 28 } 29 } 30 return false; 31} 32 33private boolean isLatin1() { 34 return COMPACT_STRINGS && coder == LATIN1; 35} 36 37###StringLatin1.equals| 38@HotSpotIntrinsicCandidate 39 public static boolean equals(byte[] value, byte[] other) { 40 if (value.length == other.length) { 41 for (int i = 0; i < value.length; i++) { 42 if (value[i] != other[i]) { 43 return false; 44 } 45 } 46 return true; 47 } 48 return false; 49 } 50 51###StringUTF16.equals| 52@HotSpotIntrinsicCandidate 53 public static boolean equals(byte[] value, byte[] other) { 54 if (value.length == other.length) { 55 int len = value.length >> 1; 56 for (int i = 0; i < len; i++) { 57 if (getChar(value, i) != getChar(other, i)) { 58 return false; 59 } 60 } 61 return true; 62 } 63 return false; 64 }
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

补充关于equals的比较方式

补充(equals比较)Object中的equals比较的是地址languagepublicbooleanequals(Objectobj)return(thisobj);java.lang.String类中equals的方法equals判断相等依据策略:如果与目标相等返回0,小于目标返回值小于0,大于目标返回值大于0lan

Android So动态加载 优雅实现与原理分析

背景:漫品Android客户端集成适配转换功能(基于目标识别(So库35M)和人脸识别库(5M)),导致apk体积50M左右,为优化客户端体验,决定实现So文件动态加载.!(https://oscimg.oschina.net/oscnet/00d1ff90e4b34869664fef59e3ec3fdd20b.png)点击上方“蓝字”关注我