Most efficient way to increment a Map value in Java

Some test results I’ve gotten a lot of good answers to this question–thanks folks–so I decided to run some tests and figure out which method is actually fastest. The five methods I tested are these: the “ContainsKey” method that I presented in the question the “TestForNull” method suggested by Aleksandar Dimitrov the “AtomicLong” method suggested … Read more

Any implementation of Ordered Set in Java?

Take a look at LinkedHashSet class From Java doc: Hash table and linked list implementation of the Set interface, with predictable iteration order. This implementation differs from HashSet in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is the order in which elements were inserted into the … Read more

HashSet vs. List performance

A lot of people are saying that once you get to the size where speed is actually a concern that HashSet<T> will always beat List<T>, but that depends on what you are doing. Let’s say you have a List<T> that will only ever have on average 5 items in it. Over a large number of cycles, if a single item … Read more

Any implementation of Ordered Set in Java?

Take a look at LinkedHashSet class From Java doc: Hash table and linked list implementation of the Set interface, with predictable iteration order. This implementation differs from HashSet in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is the order in which elements were inserted into the … Read more

How to easily initialize a list of Tuples?

c# 7.0 lets you do this: If you don’t need a List, but just an array, you can do: And if you don’t like “Item1” and “Item2”, you can do: or for an array: which lets you do: tupleList[0].Index and tupleList[0].Name Framework 4.6.2 and below You must install System.ValueTuple from the Nuget Package Manager. Framework 4.7 and above It is built … Read more