String concat_str0 = "abc";
String concat_str1 = "bcd";
String concat = concat_str0.concat(concat_str1);
System.out.println("拼接字符串concat:"+concat);//"abc"+"bcd"
System.out.println("------------------------------");
String contains_str0 = "abcdefg";
String contains_str1 = "cde";
boolean contains = contains_str0.contains(contains_str1);
System.out.println("判断一个字符串中是否包含某一个小串contains:"+contains);
System.out.println("------------------------------");
String startsWith_str0 = "abcdefg";
String startsWith_str1 = "ab";
boolean startsWith = startsWith_str0.startsWith(startsWith_str1);
System.out.println("判断个字符串是否以另一个字符串开头startsWith:"+startsWith);
System.out.println("------------------------------");
String equalsIgnoreCase_str0 = "abcdefg";
String equalsIgnoreCase_str1 = "Abcdefg";
boolean equalsIgnoreCase = equalsIgnoreCase_str0.equalsIgnoreCase(equalsIgnoreCase_str1);
System.out.println(" 判断 和另一个字符串的内容是否相同(不区分大小写的比较)equalsIgnoreCase:"+equalsIgnoreCase);
System.out.println("------------------------------");
String getBytes_str0 = "abc";
byte[] bytes = getBytes_str0.getBytes();
System.out.print("[");
for(int i = 0; i < bytes.length; ++i)
{
System.out.print(bytes[i]+" ");
}
System.out.println("]");
System.out.println("------------------------------");
String indexOf_first_ch0 = "abcdef";
int indexOf_first_ch = indexOf_first_ch0.indexOf('d');
System.out.println("在字符串中查找 某个字符第一次出现的索引indexOf:"+indexOf_first_ch);
System.out.println("------------------------------");
String indexOf_first_from_ch0 = "abcdef";
int indexOf_first_from_ch = indexOf_first_from_ch0.indexOf('d', 4);
System.out.println("从某个位置开始来算, 某个字符第一次出现的索引indexOf:"+indexOf_first_from_ch);
System.out.println("------------------------------");
String indexOf_first_str0 = "abcdefg";
int indexOf_first_str = indexOf_first_str0.indexOf("ef");
System.out.println("在字符串中查找 某个小字符串第一次出现的索引indexOf:"+indexOf_first_str);
System.out.println("------------------------------");
String indexOf_first_from_str0 = "abcdef";
int indexOf_first_from_str = indexOf_first_from_str0.indexOf('d', 4);
System.out.println("从某个位置开始来算, 某个字符串第一次出现的索引indexOf:"+indexOf_first_from_str);
System.out.println("------------------------------");
String lastIndexOf_str0 = "abcdefg";
int lastIndexOf = lastIndexOf_str0.lastIndexOf('d');
System.out.println(" 字符串中查找(倒着查找) 某个小字符串第一次出现的索引lastIndexOf:"+lastIndexOf);
System.out.println("------------------------------");
String replaceAll_str0 = "abfgcdeffghijfgk";
String replaceAll = replaceAll_str0.replace("fg", "oo");
System.out.println("在一个字符串中,用一个新的小串,把所有的老小串 替换掉replaceAll:"+ replaceAll);
System.out.println("------------------------------");
String replaceFirst_str0 = "abcdfgegfghijk";
String replaceFirst = replaceFirst_str0.replaceFirst("fg","oo");
System.out.println("在一个字符串中, 用一个新的小串,第一个出现的老小串 替换掉replaceFirst:"+ replaceFirst);
System.out.println("------------------------------");
String split_str0 = "ab,cd,ef,gh";
String[] split = split_str0.split(",");
System.out.print("切割字符串split:"+"[ ");
for(int i = 0; i < split.length; ++i){
System.out.print(split[i]+" ");
}
System.out.println(" ]");
System.out.println("------------------------------");
String substring_str0 = "abcdefg";
String substring = substring_str0.substring(2);
System.out.println("截取字符串substring:"+substring);
System.out.println("------------------------------");
String substring_from_str0 = "abcdefg";
String substring_from = substring_from_str0.substring(2,5);
System.out.println("截取字符串指定位置substring:"+substring_from);
System.out.println("------------------------------");
String toCharArray_str0 = "abcdefg";
char[] toCharArray_chars = toCharArray_str0.toCharArray();
System.out.print("把自已字符串转换为一个字符数组toCharArray:"+"[ ");
for(int i = 0; i < toCharArray_chars.length; ++i){
System.out.print(toCharArray_chars[i]+" ");
}
System.out.println("]");
System.out.println("------------------------------");
String str0 = "AbbcDDef";
String toUpperCase = str0.toUpperCase();
String toLowerCase = str0.toLowerCase();
System.out.println("把字符串转大写toUpperCase:"+toUpperCase);
System.out.println("------------------------------");
System.out.println("把字符串转小写toLowerCase:"+toLowerCase);
System.out.println("------------------------------");
String trim_str0 = " a b c d ";
String trim = trim_str0.trim();
System.out.println("把字符两端的空格去除掉trim:"+trim);
System.out.println("------------------------------");
char []valueOf_chars = {'a','b'};
String valueOf = String.valueOf(valueOf_chars);
System.out.println("把任意的东西转换为字符串valueOf:"+valueOf);
System.out.println("------------------------------");
手机扫一扫
移动阅读更方便
你可能感兴趣的文章