I believe that you can achieve what you want by the following method:
public static int parseIntWithDefault(String s, int default) {
try {
return Integer.parseInt(s);
} catch(NumberFormatException e) {
return default;
}
}
and now just assign:
int int_userid = parseIntWithDefault(userId, 0);
Please have in mind, that using Java
one should use Java good practices about formatting the code. int_userid
is definitely something to improve.