What exactly does this mean?
String path = selectedPath.equals("/") ? "/" : selectedDir;
What I think it is saying is set path to the selectedPath if it equals "/" and if it doesn't set the path to selectedDir.
What exactly does this mean?
String path = selectedPath.equals("/") ? "/" : selectedDir;
What I think it is saying is set path to the selectedPath if it equals "/" and if it doesn't set the path to selectedDir.
The ternary operator is a way to do an "if else" that actually returns a value so if you have a function such as:
int f(boolean a, int b, int c) {
if (a) {
return b;
} else {
return c;
}
}
and then you call the function like:
int y = f(b > c, b, c);
you can avoid the function by doing:
int y = b > c ? b : c;
So it means that, if you have the following expresion:
a ? b : c
it means:
if a is true, then return b; otherwise return c.
Specifically in your case, it means, as you said, that if selectedPath is equal to "/" then return "/" otherwise return the value at the right of the ':' character.