Collection key1 = accounts.keySet(); //accounts = A hashmap with integer,integer Iterator iter = key1.iterator(); //Create the iterator while (iter.hasNext())//Check if there is more to go to { iter.next(); //This is the object you get from the iterator, it also advances the iterator by one }