1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| "Hello".contains("ll"); "Hello".indexOf("l"); "Hello".lastIndexOf("l"); "Hello".startsWith("He"); "Hello".endsWith("lo"); "Hello".substring(2);
" \tHello\r\n ".trim();
"".isEmpty(); " ".isEmpty(); " \n".isBlank(); " Hello ".isBlank();
s.replace('l', 'w');
String s = "A,,B;C ,D"; s.replaceAll("[\\,\\;\\s]+", ",");
String s = "A,B,C,D"; String[] ss = s.split("\\,");
String[] arr = {"A", "B", "C"}; String s = String.join("***", arr);
String s = "Hi %s, your score is %d!"; System.out.println(s.formatted("Alice", 80)); System.out.println(String.format("Hi %s, your score is %.2f!", "Bob", 59.5));
String.valueOf(45.67);
int n1 = Integer.parseInt("123"); int n2 = Integer.parseInt("ff", 16);
byte[] b1 = "Hello".getBytes(); byte[] b2 = "Hello".getBytes("UTF-8"); byte[] b2 = "Hello".getBytes("GBK"); byte[] b3 = "Hello".getBytes(StandardCharsets.UTF_8);
byte[] b = ... String s1 = new String(b, "GBK"); String s2 = new String(b, StandardCharsets.UTF_8);
|