1. 鲜为人知的replaceAll技巧
System.out.println("foo[0]".replaceAll("\\[(\\d+)\\]", ".$1")); //输出: foo.0
2. 构建一个重复的字符串
System.out.println(new String(new char[3]).replace("\0", "osc")); //输出: oscoscosc
3. 按行读取字符串
BufferedReader br = new BufferedReader(new StringReader("osc1\r\nosc2\r\nosc3")); System.out.println(br.readLine()); System.out.println(br.readLine()); //输出: //osc1 //osc2
时间: 2024-11-05 11:45:23