First one:
map.put("one", new String("Hello"));//1
is almost never needed. This creates an unnecessary String
object. Although it wouldn't matter much at runtime, as it's just a single object. But definitely make a difference when used like this inside some loop. Object creation in loop is expensive operation.
The second one on the other hand:
map.put("two", "world");//2
will re-use the interned string literal from the String Literal Pool. The String literal pool is a collection of references to string objects created on heap. Java automatically interns the String literals, so that multiple usage of the same string literal doesn't create a new string object everytime. When a string literal is encountered first time, an object for it is created on the heap, and a reference to that object is stored on the string literal pool.
On subsequent use of the same string literal, the same string reference from the literal pool is used instead of creating a new string object on heap. And this is safe, given that Strings are immutable, we can share reference to the same String object. So, certainly this is better approach.