List<String> stringList;
//fill with strings somehow
Collection<String> stringCollection = (Collection<String>) stringList;
for(String str : stringCollection){
//will this loop be guaranteed to iterate in the order found in stringList
}
I think it is guaranteed that this for-each loop will iterate in the correct order, since the syntactic sugar actually uses an iterator and the iterator()
method is overridden in List
to have an order. Since the run time type of stringCollection
is a List
, then it will use the overridden method which starts at the beginning of the list. Is this correct?