Get first key from Dictionary

Assuming you’re using .NET 3.5: dic.Keys.First(); Note that there’s no guaranteed order in which key/value pairs will be iterated over in a dictionary. You may well find that in lots of cases you get out the first key that you put into the dictionaries – but you absolutely must not rely on that. As Skirwan … Read more

Java get last element of a collection

A Collection is not a necessarily ordered set of elements so there may not be a concept of the “last” element. If you want something that’s ordered, you can use a SortedSet/NavigableSet which has a last() method. Or you can use a List and call mylist.get(mylist.size()-1); If you really need the last element you should … Read more

List.of() or Collections.emptyList()

Collections.emptyList() does not need to create a new object for each call; it’s typical, as in OpenJDK, to just return the singleton EMPTY_LIST object. Additionally, it’s clearer that you intend to mean an empty list rather than having forgotten to fill in a placeholder. Use emptyList(); it’s both faster (up to Java target level 1.9) … Read more

Why doesn’t Dictionary support null key? [duplicate]

Why: As described before, the problem is that Dictionary requires an implementation of the Object.GetHashCode() method. null does not have an implementation, therefore no hash code associated. Solution: I have used a solution similar to a NullObject pattern using generics that enables you to use the dictionary seamlessly (no need for a different dictionary implementation). … Read more

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