• (9)字符串


    java.lang.CharSequence

    1、类结构

    public interface CharSequence
    

    2、方法

    int length();
    char charAt(int index);
    CharSequence subSequence(int start, int end);
    public String toString();
    public default IntStream chars() {
        class CharIterator implements PrimitiveIterator.OfInt {
            int cur = 0;
    
            public boolean hasNext() {
                return cur < length();
            }
    
            public int nextInt() {
                if (hasNext()) {
                    return charAt(cur++);
                } else {
                    throw new NoSuchElementException();
                }
            }
    
            @Override
            public void forEachRemaining(IntConsumer block) {
                for (; cur < length(); cur++) {
                    block.accept(charAt(cur));
                }
            }
        }
    
        return StreamSupport.intStream(() ->
                                       Spliterators.spliterator(
                                           new CharIterator(),
                                           length(),
                                           Spliterator.ORDERED),
                                       Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED,
                                       false);
    }
    public default IntStream codePoints() {
            class CodePointIterator implements PrimitiveIterator.OfInt {
                int cur = 0;
    
                @Override
                public void forEachRemaining(IntConsumer block) {
                    final int length = length();
                    int i = cur;
                    try {
                        while (i < length) {
                            char c1 = charAt(i++);
                            if (!Character.isHighSurrogate(c1) || i >= length) {
                                block.accept(c1);
                            } else {
                                char c2 = charAt(i);
                                if (Character.isLowSurrogate(c2)) {
                                    i++;
                                    block.accept(Character.toCodePoint(c1, c2));
                                } else {
                                    block.accept(c1);
                                }
                            }
                        }
                    } finally {
                        cur = i;
                    }
                }
    
                public boolean hasNext() {
                    return cur < length();
                }
    
                public int nextInt() {
                    final int length = length();
    
                    if (cur >= length) {
                        throw new NoSuchElementException();
                    }
                    char c1 = charAt(cur++);
                    if (Character.isHighSurrogate(c1) && cur < length) {
                        char c2 = charAt(cur);
                        if (Character.isLowSurrogate(c2)) {
                            cur++;
                            return Character.toCodePoint(c1, c2);
                        }
                    }
                    return c1;
                }
            }
    
        return StreamSupport.intStream(() ->
                                       Spliterators.spliteratorUnknownSize(
                                           new CodePointIterator(),
                                           Spliterator.ORDERED),
                                       Spliterator.ORDERED,
                                       false);
    }
    

    java.lang.String

    1、类结构

    public final class String
        implements java.io.Serializable, Comparable<String>, CharSequence
    

    2、非静态变量

    private final char value[];
    private int hash;
    

    3、构造方法

    public String() {
        this.value = "".value;
    }
    public String(String original) {
        this.value = original.value;
        this.hash = original.hash;
    }
    public String(char value[]) {
        this.value = Arrays.copyOf(value, value.length);
    }
    

    4、方法

    (1)拼接

    public String concat(String str) {
        int otherLen = str.length();
        if (otherLen == 0) {
            return this;
        }
        int len = value.length;
        char buf[] = Arrays.copyOf(value, len + otherLen);
        str.getChars(buf, len);
        return new String(buf, true);
    }
    

    (2)判断包含

    public boolean contains(CharSequence s) {
        return indexOf(s.toString()) > -1;
    }
    

    (3)比较

    public int compareTo(String anotherString) {
        int len1 = value.length;
        int len2 = anotherString.value.length;
        int lim = Math.min(len1, len2);
        char v1[] = value;
        char v2[] = anotherString.value;
    
        int k = 0;
        while (k < lim) {
            char c1 = v1[k];
            char c2 = v2[k];
            if (c1 != c2) {
                return c1 - c2;
            }
            k++;
        }
        return len1 - len2;
    }
    public int compareToIgnoreCase(String str) {
        return CASE_INSENSITIVE_ORDER.compare(this, str);
    }
    

    (4)以什么开始和结束

    public boolean startsWith(String prefix, int toffset) {
        char ta[] = value;
        int to = toffset;
        char pa[] = prefix.value;
        int po = 0;
        int pc = prefix.value.length;
        // Note: toffset might be near -1>>>1.
        if ((toffset < 0) || (toffset > value.length - pc)) {
            return false;
        }
        while (--pc >= 0) {
            if (ta[to++] != pa[po++]) {
                return false;
            }
        }
        return true;
    }
    public boolean endsWith(String suffix) {
        return startsWith(suffix, value.length - suffix.value.length);
    }
    

    (5)equals

    (6)indexOf

    (7)hashCode

    (8)lastIndexOf

    (9)length

    (10)matches

    (11)replace

    (12)split

    (13)subString

    (14)toCharArray(

    (15)toUpperCase()和toLowerCase

    (16)valueOf

    (17)toString

    java.lang.Appendable

    1、类结构

    public interface Appendable {
    

    2、方法

    Appendable append(CharSequence csq) throws IOException;
    Appendable append(CharSequence csq, int start, int end) throws IOException;
    Appendable append(char c) throws IOException;
    

    java.lang.AbstractStringBuilder

    1、类结构

    abstract class AbstractStringBuilder implements Appendable, CharSequence
    

    2、非静态变量

    char[] value;
    int count;
    

    3、构造方法

    AbstractStringBuilder() {
    }
    AbstractStringBuilder(int capacity) {
        value = new char[capacity];
    }
    

    4、方法

    (1)长度

    public int length() {
        return count;
    }
    public int capacity() {
        return value.length;
    }
    

    (2)追加

    AbstractStringBuilder append(AbstractStringBuilder asb) {
        if (asb == null)
            return appendNull();
        int len = asb.length();
        ensureCapacityInternal(count + len);
        asb.getChars(0, len, value, count);
        count += len;
        return this;
    }
    

    (3)charAt

    public char charAt(int index) {
        if ((index < 0) || (index >= count))
            throw new StringIndexOutOfBoundsException(index);
        return value[index];
    }
    

    java.lang.StringBuffer

    public final class StringBuffer
       extends AbstractStringBuilder
       implements java.io.Serializable, CharSequence
    

    java.lang.StringBuilder

    public final class StringBuilder
        extends AbstractStringBuilder
        implements java.io.Serializable, CharSequence
    
  • 相关阅读:
    2021-04-02:给定一个正方形或者长方形矩阵matrix,实现zigzag打印。[[0,1,2],[3,4,5],[6,7,8]]的打印顺序是0,1,3,6,4,2,5,7,8。
    2021-04-01:给定一个正方形矩阵matrix,原地调整成顺时针90度转动的样子。[[a,b,c],[d,e,f],[g,h,i]]变成[[g,d,a],[h,e,b],[i,f,c]]。
    2021-03-31:给定一个数组arr,给定一个值v。求子数组平均值小于等于v的最长子数组长度。
    2021-03-30:给定一个整数组成的无序数组arr,值可能正、可能负、可能0。给定一个整数值K,找到arr的所有子数组里,哪个子数组的累加和<=K,并且是长度最大的。返回其长度。
    2021-03-29:无序数组arr,子数组-1和1的数量一样多,请问最长子数组的长度是多少?
    04Null和Undefined
    03数据类型
    win10 命令行下 重启虚拟网卡
    JavaScript注释及命名规范
    第一个javascrpt代码
  • 原文地址:https://www.cnblogs.com/heibaimao123/p/13849836.html
Copyright © 2020-2023  润新知