Your first code assumes that the values in the map are all Strings, and so casts to String. If you're right, this is fine. But if any values in teh map are not Strings, the cast fails, and you get an exception.
The second code makes no assumptions about whether the values are Strings or something else. It just calls toString() on any object it finds. It also handles null.
If you're using JDK 5 or later, the map should be declared using generics, and so you should know exactly what type is in it. Then no guessing or casting is necessary. If you have
then later you can use
and there's no need for a cast - the compiler knows that the value is already a String. Or possibly null.
However if you have
then later you should use
Here the only advantage of using valueOf() instead of toString() is that valueOf() handles null without throwing an exception.