Top Useful Tips
Arrays.sort(A, (a, b) -> a[0] - b[0]);
int[] B = A.clone();
PriorityQueue<String> pq= new PriorityQueue<String>(5, (a,b) -> a.length() - b.length());
TreeMap<Integer,String> map = new TreeMap<Integer,String>(); // Balanced Tree.
treeMap.floorKey(2) // find the closest lower key than 2 in the map!
Collections, sort, print
# Sort #
Collections.sort(events, (a, b) -> a.value - b.value); // List Sort
Arrays.sort(A, (a, b) -> a[0] - b[0]); // Array sort.
# Array to List #
Arrays.asList(A);
# Print #
list.stream().forEach(System.out::println);
# Copy Array #
int[] B = A.clone()
Comparators
PriorityQueue with comparator
PriorityQueue<Interval> pq = new PriorityQWueue<>((a, b) -> a.start - b.start)
// new comparator -> <Type> -> int compare(a, b)
Arrays.sort(A, new Comparator<int[]>() {
public int compare(int[] i1, int[] i2) {
return i1[0] - i2[0];
}
});
// Copy array