What is the meaning of ":"?

76 views Asked by At

I have been watching some LinkedList videos to try and understand what it is. But I see a lot of people having code like

for(String x : model)

Can anyone help me understand what ":" does in this code besides attaching x to "model" or is that all it does?

4

There are 4 answers

0
Sirmyself On BEST ANSWER

It means the loop will iterate through each object of the list

String x declares a String named x

model is the list of String you want to iterate through

: is the operator making the compiler doing this operation.

You can read the for like this : For each String in model, use x as variable and do the following operations.

you can then use x to do the operations you want on each elements of the list

0
jurez On

In this context, : literally means in.

0
Mureinik On

This is the syntax of the enhanced for loop. It marely means that you're iterating over all the elements in model, where in each iteration the String x is assigned with the current element so you can use in the loop's body.

0
Swatarianess On

Similar to mathematical notation that represents elements in a set.

Read left to right; For all string's x that are elements in model, do .