首页 > 代码库 > Java 语法 索引 ----- 字符串(String)

Java 语法 索引 ----- 字符串(String)

组合吃烤串的各种方法

String a = "Hello";String b = new String(" World");//在循环里面的话要小心用String c = a+b; // Hello World          a += b; // Hello WorldString x = "Hello " + "World";

 

比较字符串

boolean x = a.equals(b); // compares stringboolean y = (a == b); // compares address

 

StringBuffer

//虽是sb但是确实很聪明StringBuffer sb = new StringBuffer("Hello");sb.append(" World"); // add to end of string 添加sb.delete(0, 5); // remove 5 first characters 删除sb.insert(0, "Hello"); // insert string at beginning 插入String s = sb.toString();