尚硅谷Java常用类学习笔记

Java常用类

一、字符串类 1、String 类 String类:构造字符串对象 字符串的字符使用Unicode字符编码,一个字符占两个字节 底层用char型数组实现

字符串对象操作

public int length() public char charAt(int index):返回在指定index位置的字符。index从0开始

public boolean equals(Object anObject):比较两个字符串是否相等。相等返回true。否则返回false

public int compareTo(String anotherString)

public int indexOf(String s):返回s字符串在当前字符串中首次出现的位置。若没有,返回-1

public int indexOf(String s ,int startpoint):返回s字符串从当前字符串startpoint位置开始的,首次出现的位置。

public int lastIndexOf(String s):返回s字符串最后一次在当前字符串中出现的位置。若无,返回-1 public int lastIndexOf(String s ,int startpoint)

public boolean startsWith(String prefix):判断当前字符串是否以prefix开始。

public boolean endsWith(String suffix):判断当前字符串是否以suffix结束。

 public boolean regionMatches(int firstStart,String other,int otherStart ,int length):判断当前字符串从firstStart开始的子串与另一个字符串other从otherStart开始,length长度的字串是否equals 字符串对象修改

public String substring(int startpoint)

public String substring(int start,int end):返回从start开始到end结束的一个左闭右开的子串。start可以从0开始的。

pubic String replace(char oldChar,char newChar)

public String replaceAll(String old,String new) public String trim():去除当前字符串中首尾出现的空格,若有多个,就去除多个。

public String concat(String str):连接当前字符串与str public String[] split(String regex):按照regex将当前字符串拆分,拆分为多个字符串,整体返回值为String[]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值