<AptiCode/>

Question 746: Suppose that you would like to create an instance of a newMapthat has an iteration order that is the same as the iteration order of an existing instance of aMap. Which concrete implementation of theMapinterface should be used for the new instance?

tcs
wipro
infosys
general
aptitude
objects-and-collections
java-programming

The iteration order of aCollectionis the order in which an iterator moves through the elements of theCollection. The iteration order of aLinkedHashMapis determined by the order in which elements are inserted.When a newLinkedHashMapis created by passing a reference to an existing Collection to the constructor of aLinkedHashMaptheCollection.addAllmethod will ultimately be invoked.The addAll method uses an iterator to the existing Collection to iterate through the elements of the existing Collection and add each to the instance of the newLinkedHashMap.Since the iteration order of theLinkedHashMapis determined by the order of insertion, the iteration order of the newLinkedHashMapmust be the same as the interation order of the oldCollection.