随堂笔记160303String

本节课也是关于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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值