How many characters can a String have?

Since String.length() method returns an int we could guess that the maximum length would be Integer.MAX_VALUE characters. That’s not correct. Let’s forget about Unicode for now, and try to create the longest possible string by repeating a lowercase letter a.

Read More

WeakHashMap is not thread-safe

java.util.WeakHashMap can be used as in-memory cache, allowing keys to expire when they are weakly reachable. Unfortunately this class is not thread-safe. It’s entirely possible that un-synchronized invocation of the WeakHashMap.get(Object) method will result in infinite busy waiting loop starving all other threads.

Read More