Java中String类常⽤⽅法String类判断功能:
判断字符串是否以指定字符串开头
String FOREVER_GWC = "FOREVER_GWC";
boolean flag = FOREVER_GWC.startsWith("F");
System.out.println(flag);
判断字符串是否以指定字符串结尾
String FOREVER_GWC = "FOREVER_GWC";
boolean flag = dsWith("C");
System.out.println(flag);
判断两个字符串内容是否相同
String FOREVER_GWC_FIRST = "FOREVER_GWC";
String FOREVER_GWC_SECOND = "FOREVER_GWC";
boolean flag = FOREVER_GWC_FIRST.equals(FOREVER_GWC_SECOND);
System.out.println(flag);
判断两个字符串忽略⼤⼩写后内容是否相同
String FOREVER_GWC_FIRST = "FOREVER_GWC";
String FOREVER_GWC_SECOND = "FOREVER_GWC";
boolean flag = FOREVER_GWC_FIRST.equalsIgnoreCase(FOREVER_GWC_SECOND);
System.out.println(flag);
判断字符串中是否含有指定字符串
String FOREVER_GWC = "FOREVER_GWC";
System.out.println(ains("GWC"));
判断指定字符串的值是否为空
String FOREVER_GWC = "FOREVER_GWC";
System.out.println(FOREVER_GWC.isEmpty());
String类获取功能:
java中split的用法
获取字符串长度
String FOREVER_GWC = "FOREVER_GWC";
int length = FOREVER_GWC.length();
System.out.println(length);
获取指定位置的字符
String FOREVER_GWC = "FOREVER_GWC";
System.out.println(FOREVER_GWC.charAt(0));
正序查指定字符串在原字符串中的位置
String FOREVER_GWC = "FOREVER_GWC";
System.out.println(FOREVER_GWC.indexOf("F"));
倒序查指定字符串在原字符串中的位置
String FOREVER_GWC = "FOREVER_GWC";
System.out.println(FOREVER_GWC.lastIndexOf("E"));  从指定位置正序查指定字符串在原字符串中的位置  String FOREVER_GWC = "FOREVER_GWC";
System.out.println(FOREVER_GWC.indexOf("E", 3));
从指定位置倒序查指定字符串在原字符串中的位置  String FOREVER_GWC = "FOREVER_GWC";
System.out.println(FOREVER_GWC.lastIndexOf("E", 10));从指定位置截取字符串
String FOREVER_GWC = "FOREVER_GWC";
System.out.println(FOREVER_GWC.substring(8));
从指定区间截取字符串
String FOREVER_GWC = "FOREVER_GWC";
System.out.println(FOREVER_GWC.substring(0, 7)); String类转化⽅法:
将字符串转换为char类型的数组
String FOREVER_GWC = "FOREVER_GWC";
char [] charArray = CharArray();
for (char date : charArray)
{
System.out.println(date);
}
将字符串转换为⼤写字符串
String FOREVER_GWC = "forever_gwc";
System.out.println(UpperCase());  将字符串转换为⼩写字符串
String FOREVER_GWC = "FOREVER_GWC";
System.out.println(LowerCase()); String类构造⽅法
StringBuilder name = new StringBuilder();
name.append("FOREVER");
name.append("GWC");
String names = String();
System.out.println(names);
其他常⽤⽅法:
去除字符串两端空格:
String FOREVER_GWC = " FOREVER_GWC ";
System.out.println(im());
按指定符号分割字符串
String FOREVER_GWC = "FOREVER_GWC";
String strs[] = FOREVER_GWC.split("_");
for(String str : strs)
{
System.out.println(str);
}
将指定字符串替换为另⼀字符串
String FOREVER_GWC = "forever_gwc";
System.out.println(place("forever_gwc", "FOREVER_GWC"));
将出现的第⼀个指定字符串替换为另⼀字符串
String FOREVER_GWC = "GWCGWCGWCGWCGWC";
System.out.println(placeFirst("GWC", "gwc"));
在原字符串后增加指定字符串
String FOREVER_GWC = "FOREVER";
System.out.println(at("_GWC"));
>>>>>>>>>>####
待补充
1. compareTo:根据字符串中每个字符的Unicode编码进⾏⽐较
compareToIgnoreCase:根据字符串中每个字符的Unicode编码进⾏忽略⼤⼩写⽐较valueOf:其他类型转字符串
codePointAt:指定下标的字符的Unicode编码
format:格式化字符串
getBytes:获取字符串的字节数组
join:以某字符串,连接某字符串数组
matches:字符串是否匹配正则表达式
replaceAll:带正则字符串替换

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。

发表评论