String类的一些方法

package com.string;
public class StringTest {
public static void main(String[] args){
String a= "abcd";
//得到数组中的值
char c =a.charAt(1);
System.out.println(c);
////
// String a = "abc";
// String b ="abc";
// //比较两个字符串是否相等 不区分大小写
// System.out.println(a.equalsIgnoreCase(b));
// //得到指定字符串,第一次出现自c字符串的下表,如果c中不包含该字符串返回-1
// String c ="abcdebcd";
// int index = c.indexOf("bc");
// //得到指定字符串,最后一次出现在c字符串
// int last =c.lastIndexOf("bc");
// System.out.println(index+""+last);
// //得到字符串的长度
// int len =c.length();
// System.out.println(len);

String d = "abcbcdefad";
//将指定的字符串替换为新字符串
d = d.replace("ab", "");
System.out.println(d);


String e ="abcefg";
//从下标为2开始,截取字符串
e = e .substring(2);
System.out.println(e);

String f ="abcdefg";
//从下标为1开始,4结束,截取字符串,包含1不包含4
f = f.substring(1,4);
System.out.println(f);

String g =" a b c d  e f";
//去掉前后的空格
g=g.trim();
System.out.println(a+"*");



}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值