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[]);  

Java Queue, Stack

FIFO: Queue  FILO: Stack Queue Since java 5 we can use queue by importing import java.util.Queue; Insert an item at the end of a queue and pop out from the head of the queue. Queue is an interface that there are several implementing classes, but the most used class is LinkedList Queue<TreeNode> queue = new … More Java Queue, Stack