> For the complete documentation index, see [llms.txt](https://298073941.gitbook.io/memo/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://298073941.gitbook.io/memo/2020-05/java-bu-chong/zi-fu-chuan.md).

# 字符串

java字符串是我们平时使用比较多的数据结构，本质是char数组

一般操作有拼接，可使用+，底层会自动转为stringbuilder，append

注意string的==比较

```
String abc = new String("abc");
print abc == "abc" //false
print abc.equal("abc") // true
```

这里是因为使用了new String 创建了一个新的string导致引用不一样

StringBuilder 线程不安全 速度快一些

StringBuffer 线程安全

常用函数

| 方法名            | 作用                  |
| -------------- | ------------------- |
| length()       | 长度                  |
| charAt(i)      | 返回字符串位置i的char       |
| equal(s)       | 字符串内容比较             |
| indexOf(str)   | 字符串第一次出现的下标         |
| replace(oS,nS) | ns替换os              |
| getBytes()     | 默认编码字符串返回byte\[]    |
| split(char)    | 根据这个char拆分string\[] |
| toUpperCase()  | 转为大写                |
| toLowerCase()  | 转为小写                |

有很多第三方提供了大量string操作，可以去了解下
