JDK之String源码解读(五)

版权声明:本文为博主原创文章,欢迎转载,转载请标明出处。 https://blog.csdn.net/qq_32523587/article/details/86559284

目录

 

startsWith(String prefix, int toffset)

startsWith(String prefix)

endsWith(String suffix)

hashCode()

indexOf(int ch)

lastIndexOf(int ch)


startsWith(String prefix, int toffset)

对比情况如下图所示:

作用:判断当前String 是否在指定的位置toffset是以指定的前缀prefix开头的。

startsWith(String prefix)

如下图所示:

作用:判断当前String 是否是以指定的前缀prefix开头的。

endsWith(String suffix)

作用:判断当前String 是否是以指定的后缀suffix结束的。


hashCode()

作用:返回当前String的hashCode。String的hashCode计算方法:s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]

indexOf(int ch)

作用:获取第一个等于指定参数的字符所在的位置。

其中,indexOfSupplementary(int ch, int fromIndex)方法如下:

lastIndexOf(int ch)

作用:获取最后一个等于指定参数的字符所在的位置。

其中,双字节的处理方法如下:

猜你喜欢

转载自blog.csdn.net/qq_32523587/article/details/86559284
今日推荐