if(something == "") return;
Does it mean if something is " " aka empty, just exit the function? I tried searching different answers. None of them explained what this piece of code does.
if(something == "") return;
Does it mean if something is " " aka empty, just exit the function? I tried searching different answers. None of them explained what this piece of code does.
return
immeadiately exits the current function you're in.
That means that no code is executed after the return has been executed with one exception:
try {
...
return;
} finally {
// this code will be executed even if a return is called inside the 'try' block!
}
You can use return;
(no value returned) when you want to exit a void
method.
On a sidenote: Don't compare strings with ==
. Compare strings with .equals(...)
.
Back to your original question: If the code was like this:
if (something.equals("")) return;
Then yes, it would mean that the method returns if 'something' is empty!
You have 2 errors.
=
doesn't check if something is equal. =
assigns a value to a variable. You need to use ==
for primitive datatypes (like integer).
For strings you need to use string.equals(anotherString)
to check if something is equal