What is the difference between String.valueOf() and new String()? When would you use one over the other?
example 1:
public String fun(){
int foo = 55;
return String.valueOf(foo);
}
example 2:
public String fun(){
int foo = 55;
return new String(foo);
}
Update: Yes, the second example doesn't compile as pointed out by others below. I didn't realize it because I have been using new String("something" + foo) and it has worked, as pointed out by fastcodejava. So is there a difference between the two if I use new String("something" + foo) or String.valueOf(foo) ?
Integer.toString(foo)