String详解
发布日期:2021-05-14 13:03:57 浏览次数:21 分类:精选文章

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

���������������������String ���������������������������������������������������������������������������������������������������������������������������������������������������������������String������������������������������������������������������������������

1. String���������

���Java������String���������������������char���������������������������������������������char���������������final������������������������������������String������������������������������String������������������������������������������������������������������������

���������������

String������������������������������������

  • value[]���������������������������������������int������
  • hash���������String���������������������������0���

2. String������������

String ���������������������������������value������������������������������������������������������

  • src������������������������������������������������������String���char������������������������StringBuilder��� StringBuffer������
  • offset���������src���������������������
  • count���������������������value���������������������
  • charset���������������������

���������������������������������������������������������������������������������������������������

3. ���������������������

3.1 ������������������

String���������������������������������������������������

public int getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
if (srcBegin < 0) { // ������������������������
throw new StringIndexOutOfBoundsException(srcBegin);
}
if (srcEnd > value.length) { // ������������������������������
throw new StringIndexOutOfBoundsException(srcEnd);
}
if (srcBegin > srcEnd) { // ������������������
throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
}
System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
}

3.2 ������������

  • equals(Object anObject)���������������String���������������������������������������������������

  • regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)���������������������������������������������������������������������������

  • compareTo(String anotherString)������������������Unicode���������������������������������

  • hashCode()���������String���������������

NOTE���compareTo���compareToIgnoreCase������������������������������������������������������������������������������������������������������������������

3.3 ���������������������

  • startsWith(String prefix)������������������������������������������������

  • endsWith(String suffix)������������������������������������������������������������������������������startsWith���������������

���������

public boolean endsWith(String suffix) {
return startsWith(suffix, value.length - suffix.value.length);
}

4. ������������

4.1 ������������

String���������������������������������indexOf���lastIndexOf���

public int indexOf(int ch, int fromIndex) {
// ������������������������
}
public int lastIndexOf(int ch, int fromIndex) {
// ������������������������
}

���������������������������������������������������������������������������������������

4.2 ������������������

String������������������������������������������

public int indexOf(String str, int fromIndex) {
// ������������������������
}

���������������������������������������������

5. ���������������

5.1 ������������������

String������������������������������������

  • substring(int beginIndex)������������������������������������������������������������������

  • substring(int beginIndex, int endIndex)������������������������������������������������������������������

  • 5.2 ���������������

    • concat(String str)���������������������������������������������������������

    • String.join(CharSequence delimiter, CharSequence... elements)������������������������������������������������������������������

    5.3 ������������

    • matches(String regex)���������������������������������������������������������������

    6. ���������������

    ������������������������������toLowerCase���toUpperCase������

    6.1 ������������

    • toLowerCase()���������������������������������������

    • toUpperCase()���������������������������������������

    6.2 ������������

    • trim()���������������������������������������������������

    7. ������������

    • toCharArray()���������������������������������������

    • intern()������������������������������������������������������

    ���������������String������������������������������������Java������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:JSP的JNDI简单编写
    下一篇:高效的SQLSERVER分页查询

    发表评论

    最新留言

    逛到本站,mark一下
    [***.202.152.39]2025年04月30日 01时58分07秒

    关于作者

        喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
    -- 愿君每日到此一游!

    推荐文章