Java – String

String, StringBuilder, StringBuffer String is a unchangeable object(although it does not belong to the 8 primitive types). If we change the string, we rebuild a new object that a reference “points” to it. So for an an object that always changes, the speed will slow down (JVM GC). At this time, we use StringBuffer(not thread safe) or StringBuilder(thread … More Java – String

Java Notes(3) summarize

Input: map: map.put(key,value); set: set.add(object); list: list.add(object); Class type and Primitive type: Used in map ,list: int -> Integer, boolean -> Boolean, char -> Character Contains: set.contains(object); length: list: list.size(); sort: array: Arrays.sort(int[]);  

DFS notes

When to use dfs? Generally speaking, there are several situations as follows: Combination Sample answer: combination sum2  Key Point: 1) sorting before dfs 2) use Index to help remove duplicates 3) consider out of boundary question whenever using arrays Use DFS without recursion: Use STACK(Every time pop an item, push the it’s children, thus accomplish DFS) Stack FILO … More DFS notes

Java Notes(2)

Collection, Collections Collection: interface(List :LinkedList, ArrayList; Vector: Stack; Set) Collections : a tool class e.g. Collections.sort(list) Collections.sort vs Arrays.sort Collections.sort deals with object that from collection interface(list,set,vector,stack), arrays deals with array object. e.g. Class temp contains an array and a list. Arrays.sort(temp.array) Collections.sort(temp.list) Comparator Default sorting in sort method uses merge sort. If we want … More Java Notes(2)