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.

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

// 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