import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.List;/**
* ClassName StringApiTest
* Description
* Create by shensiback
* Date 2021-04-20 22:38
**/publicclassStringApiTest{publicstaticint num =1;publicstaticvoidmain(String[] args){
String str ="this is stringApiTest ";print("charAt",str.charAt(0));print("codePointAt",str.codePointAt(0));print("offsetByCodePoints",str.offsetByCodePoints(1,2));print("compareTo",str.compareTo("this is stringApiTest1"));print("compareTo",str.compareTo("this is a StringApiTest"));print("compareTo",str.compareTo("this is stringApiTest"));print("codePoints",Arrays.toString(str.codePoints().toArray()));print("isEmpty",str.isEmpty());print("isEmpty","".isEmpty());print("equals",str.equals("123"));print("equals",str.equals("this is stringApiTest"));print("equalsIgnoreCase",str.equalsIgnoreCase("THIS IS STRINGAPITEST"));print("equalsIgnoreCase",str.equalsIgnoreCase("THIS is stringApiTest"));print("startsWith",str.startsWith("this is"));print("startsWith",str.startsWith("this not is"));print("endsWith",str.endsWith("Test"));print("endsWith",str.endsWith("test"));print("indexOf",str.indexOf("is"));print("indexOf",str.indexOf("is",10));print("indexOf",str.indexOf(32));print("indexOf",str.indexOf(32,10));print("lastIndexOf",str.lastIndexOf("est"));print("lastIndexOf",str.lastIndexOf("est",10));print("lastIndexOf",str.lastIndexOf(32));print("lastIndexOf",str.lastIndexOf(32,10));print("length",str.length());print("codePointCount",str.codePointCount(0,3));print("replace",str.replace(" is "," not is "));print("substring",str.substring(5));print("substring",str.substring(5,7));print("toLowerCase",str.toLowerCase());print("toUpperCase",str.toUpperCase());print("trim",str.trim());print("join",String.join(str,"header "," -- 001 "," -- 002 "));}publicstatic<T>voidprint(String name,T t){
System.out.print(name +" : ");
System.out.println(t.toString());}}
输出
charAt : t
codePointAt : 116
offsetByCodePoints : 3
compareTo : -17
compareTo : 18
compareTo : 1
codePoints : [116, 104, 105, 115, 32, 105, 115, 32, 115, 116, 114, 105, 110, 103, 65, 112, 105, 84, 101, 115, 116, 32]
isEmpty : false
isEmpty : true
equals : false
equals : false
equalsIgnoreCase : false
equalsIgnoreCase : false
startsWith : true
startsWith : false
endsWith : false
endsWith : false
indexOf : 2
indexOf : -1
indexOf : 4
indexOf : 21
lastIndexOf : 18
lastIndexOf : -1
lastIndexOf : 21
lastIndexOf : 7
length : 22
codePointCount : 3
replace : this not is stringApiTest
substring : is stringApiTest
substring : is
toLowerCase : this is stringapitest
toUpperCase : THIS IS STRINGAPITEST
trim : this is stringApiTest
join : header this is stringApiTest -- 001 this is stringApiTest -- 002