You need to look through the choice of classes and methods in the collection framework to find the combination that will do what you want.