When to use a Map instead of a List in Java?

Java map: An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. Java list: An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access … Read more

C# Convert List to Dictionary

Try this: The first lambda lets you pick the key, the second one picks the value. You can play with it and make values differ from the keys, like this: If your list contains duplicates, add Distinct() like this: EDIT To comment on the valid reason, I think the only reason that could be valid … Read more

Get dictionary key by value

Values do not necessarily have to be unique, so you have to do a lookup. You can do something like this: If values are unique and are inserted less frequently than read, then create an inverse dictionary where values are keys and keys are values.