String/StringBuilder

String

String str = "123";
str.length();
str.charAt(index);

char[] word = str.toCharArray();
String str_again = String.valueOf(word);
// str_again = new String(word);

str.substring(int beginIndex, int endIndex);

string sort
char[] chars = str.toCharArray();
Arrays.sort(chars);
String str_sorted = String.valueOf(chars);

StringBuilder

StringBuilder sb=new StringBuilder(str);

append(everything): sb.append("le") O(1)
insert: sb.insert(4, "---"); O(N)

sb.toString()
sb.length();

sb.charAt(index)
setCharAt(int index, char ch)

delete(int start, int end): remove substring
deleteCharAt(int index)

string trim() method eliminates leading and trailing spaces

你可能感兴趣的:(String/StringBuilder)