Java library
HashSet
- HashSet iterator 变成array
Iterator i=set.iterator();
int[] aim = new int[set.size()];
int j = 0;
while(i.hasNext()){
aim[j++]=(int)i.next();
}
Chacrater
- 判断is char 是数字还是字母
Character.isLetter(c) || Character.isDigit(c)
String
- int to string
String.valueOf(int); char to string
String.valueOf(char);String split
- 当引用这个function的时候,要记住如果input是“a b", 那么只会skip一个空格,其他的完全一样。(参考lc151)
The \W+ will match all non-alphabetic characters occurring one or more times. So there is no need to replace. You can check other patterns also. 但是不会开头的空格不会skip掉
String s = "This? is a sample sentence with []s.";
String[] words = s.split("\\W+");
System.out.println(words[1]);
int to string
Integer.valueOf()Arrya copy subARRAY
Arrays.copyOfRange(A, start, end); //不包含end System.arraycopy(a, start, b, start, number);
StringBuilder
- sb.append();
- sb.deleteCharAt(index);
- sb.insert(position, string);
- sb.toString();
- sb.length()
arraylist to array
String[] stockArr = stock_list.toArray(new String[stock_list.size()]);
res.stream().mapToInt(i->i).toArray()
res.stream().toArray(String[]::new)
List to Set
Set<String> dictSet = new HashSet<>(wordList);
charArray to String
new String(charArray);