IMPORTANT
方法外的变量与其通过参数传递到方法内的变量 虽然名字以及值或者说地址是一样的,但这两者根本不是同一个变量。
@Test
public void testString(){
String s1 = "78This904is325Truman9845Speaking";
s1 = s1.replaceAll("\\d+", "_");
System.out.println(s1); // _This_is_Truman_Speaking
}
@Test
public void testMatches(){
String tel = "0558-2364015";
boolean matches = tel.matches("0558-\\d{7,8}");
System.out.println(matches); // true
}
@Test
public void testSplit(){
String s1 = "I_love_Villanelle";
String[] split = s1.split("\\_");
System.out.println(Arrays.toString(split));
}
@Test
public void testByte(){
String str1 = "Villanelle";
byte[] bytes = str1.getBytes();
System.out.println(Arrays.toString(bytes)); // [86, 105, 108, 108, 97, 110, 101, 108, 108, 101]
}
Little Trick: there is letter f in StringBuffer, so, StringBuffer is Thread Safe
StringBuffer和 StringBuilder 默认的char[] 大小为16, 也可以指定, 扩容为 capacity * 2 + 2
原文:https://www.cnblogs.com/nedrain/p/13285209.html