Performance considerations for keySet() and entrySet() of Map

The most common case where using entrySet is preferable over keySet is when you are iterating through all of the key/value pairs in a Map. This is more efficient: for (Map.Entry entry : map.entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); } than: for (Object key : map.keySet()) { Object value = map.get(key); … Read more

Fastest way to search in a string collection

You could consider doing the filtering task on a background thread which would invoke a callback method when it’s done, or simply restart filtering if input is changed. The general idea is to be able to use it like this: public partial class YourForm : Form { private readonly BackgroundWordFilter _filter; public YourForm() { InitializeComponent(); … Read more

Given that HashMaps in jdk1.6 and above cause problems with multi=threading, how should I fix my code

I am the original author of the patch which appeared in 7u6, CR#7118743 : Alternative Hashing for String with Hash-based Maps‌​. I’ll acknowledge right up front that the initialization of hashSeed is a bottleneck but it is not one we expected to be a problem since it only happens once per Hash Map instance. For … Read more

In what situations is the CopyOnWriteArrayList suitable? [duplicate]

As stated on this link: CopyOnWriteArrayList is a concurrent Collection class introduced in Java 5 Concurrency API along with its popular cousin ConcurrentHashMap in Java. CopyOnWriteArrayList implements List interface like ArrayList, Vector and LinkedList but its a thread-safe collection and it achieves its thread-safety in a slightly different way than Vector or other thread-safe collection … Read more

Performance and Memory allocation comparison between List and Set

HashSet consumes about 5.5 times more memory than ArrayList for the same number of elements (although they’re both still linear), and has significantly slower iteration (albeit with the same asymptotics); a quick Google search suggests a 2-3x slowdown for HashSet iteration versus ArrayList. If you don’t care about uniqueness or the performance of contains, then … Read more

What are Reified Generics? How do they solve Type Erasure problems and why can’t they be added without major changes?

The whole point is that reified generics have support in the compiler for preserving type information, whereas type erased generics don’t. AFAIK, the whole point of having type erasure in the first place was to enable backwards compatibility (e.g. lower versioned JVMs could still understand generic classes). You can explicitly add the type information in … Read more

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