I know this is a basic question, but all the documentation I read doesn’t seem to answer my question: What does the “:” operator do?
I get the impression that if I do something like for(item : list), the for loop would go through every item of a list. Is this right?
Yes, what you have there is a for each statement. The one you have is not quite correct, if you have a
List<String>called list for example then you could do something like this:As an aside there is also another use for “:” as part of a ternary expression, e.g.
which is the same as: