Java源码----String

独自空忆成欢 提交于 2019-12-02 02:11:41

 

  

  1.1 Java对连接操作(+)和其他对象转换成string提供了特殊的支持。连接操作通过StringBuilder或者StringBuffer的append()方法。

    通过toString()方法实现转换操作。

  

  1.2 在string构造器里面放一个null,会导致空指针异常。

  

  1.3 构造器

    1.   public String() { this.value = "".value; }  

    2.  public String(String original) { this.value = original.value; this.hash = original.hash; } 

    3.  public String(char value[]) { this.value = Arrays.copyOf(value, value.length); }  Arrays.copyOf()方法内部调用的是System.arraycopy

    4. public String(char value[], int offset, int count) 

    5. public String(int[] codePoints, int offset, int count) 

    6. public String(byte ascii[], int hibyte, int offset, int count) 

    7. public String(byte ascii[], int hibyte) 

    8. public String(byte bytes[], int offset, int length, String charsetName) throws UnsupportedEncodingException 

    9. public String(byte bytes[], int offset, int length, Charset charset) 

    10. public String(byte bytes[], String charsetName) throws UnsupportedEncodingException  

    11. public String(byte bytes[], Charset charset) 

    12. public String(byte bytes[], int offset, int length)  

    13. public String(byte bytes[]) 

    14. public String(StringBuffer buffer) 

    15. public String(StringBuilder builder) 

    16. ***String(char[] value, boolean share) 这个很重要,速度很快,但共享char数组。具体看实现。

  

  1.4 内部方法

    1. public int length() 

    2. public boolean isEmpty() { return value.length == 0; } 

    3. public char charAt(int index) 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!