Why does caching of string objects perform faster?
Why skimp on braces?  Putting braces around the if-block in generateString() costs you almost nothing — not even an extra line of code.  Make it a habit to always include explicit braces so that you never write a disaster like this.  (Don't think that it can't happen to you!  Accidents often have more than one contributing factor — so don't be a contributing factor.)


private static String generateString1() {
    String str = new String("abc");
    if (cache.containsKey(str))
        return cache.get(str);
    else {
        cache.put(str, str);
        return cache.get(str);
    }
}



That could be better expressed as:

private static String generateString1() {
    String str = new String("abc");
    if (!cache.containsKey(str)) {
        cache.put(str, str);
    }
    return cache.get(str);
}


If you really don't like braces, putting the action on the same line as the if could also be acceptable:

private static String generateString1() {
    String str = new String("abc");
    if (!cache.containsKey(str)) cache.put(str, str);
    return cache.get(str);
}