java - How to convert a custom object into String in Android? -


i have object of custom class. need convert string can write file. there way out ?

thanks help.

you can't convert custom class string automatically. system has no way of knowing how want string formatted, want in , such.

you have manually implement method in custom class returns text interpretation of object. override method called tostring(). method gets called automatically if provide instance of class methods. let's if system.out.println(instance), instance's tostring() method automatically invoked.

i don't know custom class is. let's it's person class member variables string name , int age. tostring() method defined in class this:

@override public string tostring() {     return "name: " + name + ", age: " + age; } 

this provide output "name: name, age: 30".


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -