String s1 = sh.getString("name", "");
int a = sh.getInt("age", 0);
For this code I would like to show empty spaces for s1 and a if there is no input entered. When I run the application String s1 it shows empty space but int a showd 0 since the default value is 0.
Is there any way to show empty space instead of 0?
I have tried puting
Integer.parseInt("")
But it was not working.
Is there any solution for this?
Thank you.
2
Answers
You can add a condition to check if it is 0 or not. Using
null
as suggested by answer by Frank can be used but it is not preferred. Instead you can try this:You just n need to parse it as string you can’t check empty if you are using int variable So just get your age as String and also send it with string via intent you can also parse it as int after getting it from intent
Like option 1
Here you can get Like
Here you can check age is empty then if you want this value as int you can Parse it as
int a=Integer.parseInt(age);
Hope this will help you