Why should a Comparator implement Serializable?

This is not just an Android thing, the Java SDK has the same recommendation: Note: It is generally a good idea for comparators to also implement java.io.Serializable, as they may be used as ordering methods in serializable data structures (like TreeSet, TreeMap). In order for the data structure to serialize successfully, the comparator (if provided) … Read more

Simple way to sort strings in the (case sensitive) alphabetical order

If you don’t want to add a dependency on Guava (per Michael’s answer) then this comparator is equivalent: private static Comparator<String> ALPHABETICAL_ORDER = new Comparator<String>() { public int compare(String str1, String str2) { int res = String.CASE_INSENSITIVE_ORDER.compare(str1, str2); if (res == 0) { res = str1.compareTo(str2); } return res; } }; Collections.sort(list, ALPHABETICAL_ORDER); And I … Read more

When catch doesn’t actually catch anything [duplicate]

The exception (whatever it was) was caught by catch (Exception e). You didn’t log this exception, so you don’t know what it was. You should log it somehow so you know what really happened. The problem occurs when you return -1. This allows for the possibility of inconsistent ordering, which Java’s current sorting algorithm sometimes … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)