Java associative-array

Java doesn’t support associative arrays, however this could easily be achieved using a Map. E.g., Even more accurate to your example (since you can replace String with any object that meet your needs) would be to declare: See the official documentation for more information

What is a hash function in java?

The Wikipedia article will have a lot of technical information, but a simplistic view of hashing is something like the following. Imagine that there’s a magical function that can give a number to any object. Given the same object, it always return the same number. Immediately now you have a quick way to test if … Read more

Printing a java map Map – How?

I’m sure there’s some nice library that does this sort of thing already for you… But to just stick with the approach you’re already going with, Map#entrySet gives you a combined Object with the key and the value. So something like: will do what you’re after. If you’re using java 8, there’s also the new streaming approach.

What is a hash function in java?

The Wikipedia article will have a lot of technical information, but a simplistic view of hashing is something like the following. Imagine that there’s a magical function that can give a number to any object. Given the same object, it always return the same number. Immediately now you have a quick way to test if … Read more

ConcurrentHashMap and Hashtable in Java

ConcurrentHashMap uses multiple buckets to store data. This avoids read locks and greatly improves performance over a HashTable. Both are thread safe, but there are obvious performance wins with ConcurrentHashMap. When you read from a ConcurrentHashMap using get(), there are no locks, contrary to the HashTable for which all operations are simply synchronized. HashTable was released in old versions of Java whereas ConcurrentHashMap is a java 5+ … Read more