Java中String类的常用方法(常用API)——随笔(一)

一、字符串内容的比较

方法名                                                                                        说明
public boolean equals (Object anObject)                        将此字符串与指定对象进行比较。只关心字符内容是否一致!
public boolean equalsIgnoreCase (String anotherString)     将此字符串与指定对象进行比较,忽略大小写比较字符串。只关心字符内容是否一致!

 

二、遍历、替换、截取、切割                       

方法名 说明
public int length​ () 返回此字符串的长度
public char charAt​ (int index) 获取某个索引位置处的字符
public char[] toCharArray​ ():  将当前字符串转换成字符数组返回
public String substring(int beginIndex, int endIndex)  根据开始和结束索引进行截取,得到新的字符串(包前不包后)
public String substring(int beginIndex)  从传入的索引处截取,截取到末尾,得到新的字符串
public String replace(CharSequence target,CharSequence replacement) 使用新值,将字符串中的旧值替换,得到新的字符串

public String[] split(String regex) 

根据传入的规则切割字符串,得到字符串数组返回
public static String valueOf(double d) 此方法有很多重载方法,将不同类型的数据转化为String


              
                
  


posted @ 2022-02-16 11:04  Object_gl  阅读(33)  评论(0编辑  收藏  举报