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?
It means the loop will iterate through each object of the list
String x
declares a String namedx
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 eachString
inmodel
, 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