|
A small tip on String to avoid NullPointerException |
|
|
Sometimes the condition in Java class needs to compare between a constant string and a variable.
For example: variable.equals(CONSTANT_STRING);
Now suppose if the variable is not initialized then the above statement throws a null pointer exception.
To avoid this null pointer exception you can re-write the above statement:
CONSTANT_STRING.equals(variable);
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.