User Tools

Site Tools


java_primer

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
java_primer [2020/08/20 15:22] – [PriorityQueue] jrsetijava_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<String> queue = new  +PriorityQueue<String> queue = new PriorityQueue<String>(new The_Comparator()); 
-PriorityQueue<String>(new The_Comparator()); +
                  
 </code> </code>
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) - '0'
 +
 +
 +=====TRICKS=====
 +
 +====Log and division====
 +
 +  * a / b = Math.exp(Math.log(a) - Math.log(b))
 +
 +====Random====
 +
 +<code>
 +//Random number from 0 to 5
 +Random rand = new Random(); 
 +int r = rand.nextInt(6); 
 +</code>
 +
 +or
 +
 +<code>
 +//Number between 0.0 and 1.0;
 +Math.random(); 
 +</code>
  
java_primer.1597936924.txt.gz · Last modified: 2020/08/20 15:22 by jrseti