随堂笔记160303String

来源:互联网 发布:c语言完全手册pdf下载 编辑:程序博客网 时间:2024/06/11 05:26

本节课也是关于String的

一.String:

1.split() 分割字符串。

ex:

String str = "this is test";String[] str1 = str.split(" ");for(String x:str1){    System.out.println(x);}/*输出:    this    is    test*/

2.startWith() 匹配字符串开始字符

ex:

String name = "我是好人";System.out.println(name.startWith("我"));//输出true;

3.StringBuffer) 字符串缓冲区:

1.StringBuffer:修改字符串不会创建一个新的字符串,而是在原有的字符串上进行更改。

ex:

StringBuffer str = "This is";str.append("test");System.out.println(str);//输出 This is test

2.在进行字符串拼接时,使用StringBuffer速度更快

4.trim() 删除字符串首尾的空格

ex:

String sb = " This is test ";sb = sb.trim();System.out.println(sb);//打印出This is test

5.replace() 字符串字符串替换

ex:

String name = "ABC";name.replace("ABC","abc");System.out.println(name);//输入为abc
0 0