+ 9

Explain tostring() method

7th Sep 2018, 2:56 AM
Amit Haldiya
Amit Haldiya - avatar
7 Respostas
+ 11
It converts a data type to a string. E.g: int n=3; String s=Integer.toString(n); //now s also stores 3 as its value. now, you can manipulate the number using string methods note: Thanks Dan Walker for telling my mistake. We should use wrapper class to convert a data type to a string.
7th Sep 2018, 3:42 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 5
For example: int x = 5; string con = x.ToString();
7th Sep 2018, 4:46 AM
Baltazarus
Baltazarus - avatar
+ 3
Muhd Khairul Amirin Bin Yaacob Nitrocell Just to point out a primitive int won't have access to toString(), it should be an object (like Integer)
7th Sep 2018, 6:37 AM
Dan Walker
Dan Walker - avatar
+ 2
It converts the given input into string For example: int a=19; String s=a. ToString(); In above example s value also 19 if we perform addition operation it performs cancatination operation becoz it is converted into string
15th Sep 2018, 11:11 AM
Aruna Devi
+ 1
good for..
7th Sep 2018, 9:10 AM
[No Name]
[No Name] - avatar
+ 1
Aruna Devi this is almost the same as previous answers, and also has the error that int, as a primitive, has no methods so you cannot invoke toString() on it
15th Sep 2018, 11:20 AM
Dan Walker
Dan Walker - avatar
+ 1
https://www.google.co.in/url?sa=t&source=web&rct=j&url=https://www.javatpoint.com/understanding-toString()-method&ved=2ahUKEwj9_cCf_LzdAhXQfCsKHcx7BnkQFjAMegQICRAB&usg=AOvVaw1KDvr9tMXBvOAt9mdXXcaE&cshid=1537013190134 This link will help u to understand clearly
15th Sep 2018, 12:08 PM
Aruna Devi