方法 | 描述 |
---|---|
int indexOf(String s) | 字符串中指定查找,返回位置 |
int lastIndexOf(String s) | 最最后一次出现 |
char charAt(int) | 获取指定索引位置的字符 |
String substring(int beginIndex) | 切片操作(从指定位置到末尾) |
String substring(int beginIndex, int endIndex) | 切片操作(指定区间,左闭右开) |
.trim() | 去除空格 |
String replace(olderChar, newChar) | 字符串替换 |
boolean stratsWith(String prefix) | 是否存在以prefix为开头 |
boolean endsWith(String suffix) | 是否存在suffix为后缀 |
boolean equals(String otherstr) | 判断是否相同 |
boolean euqalsIngnoreCase(String otherstr) | 判断是否相同(忽略大小写) |
.toUpperCase() | 转换全大写 |
.toLowerCase() | 转换全小写 |
.split(String sign) | 依据sign分割字符串 |
字符串查找
indexOf (String s)
lastIndexOf (String str)
String str ="We are students";
int size = str.indexOf("a"); // 变量size的值是3
获取指定索引位置的字符
charAt()
String str = "hello word";
char mychar = str.charAt(5); // mychar的结果是w
获取子字符串
substring(int beginIndex)
String str = "Hello word";
String substr = str.substring(3); //获取字符串,此时substr值为lo word
substring(int beginIndex,int endIndex)
去除空格
-
字符串替换
replace(oldChar,newChar)
String str= "address";
String newstr = str.replace("a", "A");// newstr的值为Address
字符串开始与结尾
startsWith(String prefix)
返回boolean类型-
判断字符串是否相等
equals(String otherstr)
equalsIgnoreCase(String otherstr)
字母大小写转换
str.toLowerCase();
-
字符串分割
split(String sign)