java_primer
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| java_primer [2020/08/20 15:22] – [PriorityQueue] jrseti | java_primer [2020/11/19 17:19] (current) – [LinkedHashMap] jrseti | ||
|---|---|---|---|
| Line 17: | Line 17: | ||
| * But, **keys are ordered**! | * But, **keys are ordered**! | ||
| * No null keys | * No null keys | ||
| + | * keySet()and values() return in ascending order | ||
| ====LinkedHashMap==== | ====LinkedHashMap==== | ||
| + | |||
| + | **An OrderedDict!** | ||
| Same as hashMap but preserves **insertion order**. O(1) insertion and lookup. | Same as hashMap but preserves **insertion order**. O(1) insertion and lookup. | ||
| Line 139: | Line 142: | ||
| } | } | ||
| - | PriorityQueue< | + | PriorityQueue< |
| - | PriorityQueue< | + | |
| | | ||
| </ | </ | ||
| Line 162: | Line 164: | ||
| * LinkedList is better with add(), remove. | * LinkedList is better with add(), remove. | ||
| * ArrayList better with get(), set(). | * ArrayList better with get(), set(). | ||
| + | |||
| + | * Char to digit: s.charAt(num2Idx) - ' | ||
| + | |||
| + | |||
| + | =====TRICKS===== | ||
| + | |||
| + | ====Log and division==== | ||
| + | |||
| + | * a / b = Math.exp(Math.log(a) - Math.log(b)) | ||
| + | |||
| + | ====Random==== | ||
| + | |||
| + | < | ||
| + | //Random number from 0 to 5 | ||
| + | Random rand = new Random(); | ||
| + | int r = rand.nextInt(6); | ||
| + | </ | ||
| + | |||
| + | or | ||
| + | |||
| + | < | ||
| + | //Number between 0.0 and 1.0; | ||
| + | Math.random(); | ||
| + | </ | ||
java_primer.1597936924.txt.gz · Last modified: 2020/08/20 15:22 by jrseti