Difference between casting to String and String.valueOf

前端 未结 8 2035
轮回少年
轮回少年 2020-12-02 12:10

What is the difference between

Object foo = \"something\";
String bar = String.valueOf(foo);

and

Object foo = \"something\"         


        
相关标签:
8条回答
  • 2020-12-02 12:31

    in String.valueOf(); string as work typecasting all the argument passed in valueof() method convert in String and just like integer.string() convert integer into string only

    0 讨论(0)
  • 2020-12-02 12:36

    Casting means that the object needs to be of type String, while String.valueOf() can take other types as well.

    0 讨论(0)
提交回复
热议问题