What's the difference between return (string expr) and return New String(string expr)?

Viewed 8066

Is there a difference between these two methods?

public String toString() {
    return this.from.toString() + this.to.toString();
}

public String toString() {
    return new String(this.from.toString() + this.to.toString());
}

(assuming, of course, that the from.toString() and to.toString() methods are returning Strings).

Basically I'm confused about String handling in Java, because sometimes strings are treated like a primitive type even though they are class instances.

4 Answers
Related