String类的常见方法整理

		//判断:
			boolean equals(Object obj)//比较内容是否相等
			boolean equalsIgnoreCase(String str)//比较内容是否相等,忽略大小写
			boolean contains(String str)//判断字符串是否包含字符串str
			boolean startsWith(String str)//判断字符串是否以字符串str开始
			boolean endsWith(String str)//判断字符串是否以字符串str结尾
			boolean isEmpty()//判断字符串是否为空
		//获取:
			int length()//获取字符串长度
			char charAt(int index)//获取index位置的字符
			int indexOf(int ch)//返回第一次出现字符ch的索引
			int indexOf(String str)//返回第一次出现字符串str的索引
			int indexOf(int ch,int fromIndex)//返回fromIndex后第一次出现字符ch的索引
			int indexOf(String str,int fromIndex)//返回fromIndex后第一次出现字符串str的索引
			String substring(int start)//从start开始截取字符串
			String substring(int start,int end)//从start开始到end结束截取字符串
		//转换:
			byte[] getBytes()//把字符串转换为字节数组
			char[] toCharArray()//把字符串转换为字符数组
			static String valueOf(char[] chs)//把字符数组转换为字符串
			static String valueOf(int i)//把int类型的i转化为字符串
			String toLowerCase()//把字符串转换为小写
			String toUpperCase()//把字符串转换为大写
			String concat(String str)//把字符串与字符串str拼接
		//替换:
			String replace(char old,char new)//将字符串内old字符替换为new字符
			String replace(String old,String new)//将字符串内old字符串替换为new字符串
 //去空格:
	String trim()//去除首尾空格
 //比较功能:
	int compareTo(String str)//比较字符串大小
	int compareToIgnoreCase(String str) //比较字符串大小,忽略大小写

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值