文章目录
String 字符
一、string 替换 子字符串
replace replaceFirst replaceAll
String str = "abc,abc,abc,abc";
String replace = str.replace(",", "-");
System.out.println("replace---"+replace);
String replaceFirst = str.replaceFirst(",", "-");
System.out.println("replaceFirst---"+replaceFirst);
String replaceAll = str.replaceAll("abc", "http");
System.out.println("replaceAll---"+replaceAll);
replace---abc-abc-abc-abc
replaceFirst---abc-abc,abc,abc
replaceAll---http,http,http,http
二、spring 分割转 数组
splice(param1,param2) splice(param1)
splice(param1) = splice(param1,0)
说明 param1 为分割符号,可以是任何字符串,param2 为分割的数组长度
String str = "abc,abc,abc,http,http,,,,,";
String[] split1 = str.split(",", 6);
// ["abc","abc","abc","http"."http",",,,"]
String[] split2 = str.split(",", -1);
// ["abc","abc","abc","http"."http"," "," "," "]
String[] split3 = str.split(",",0);
// ["abc","abc","abc","http"."http"]
String[] split4 = str.split(",");
// ["abc","abc","abc","http"."http"]
三 indexOF() 字符串定位
String str = "abc,abc,abc,http,http,,,,";
int kk = str.indexOf(',');
int bb = str.indexOf("abc");
int ss = str.indexOf(',', 6);
int ll = str.indexOf("abc", 6);
System.out.println(kk);
System.out.println(bb);
System.out.println(ss);
System.out.println(ll);