java - HashMap values to Collection -
i have following code: hashmap<integer, string> h = new hashmap<integer, string>(); h.put(1, "a"); h.put(2, "b"); h.put(3, "c"); h.put(4, "d"); system.out.println(h); //{1=a, 2=b, 3=c, 4=d} collection<string> vals = h.values(); system.out.println(vals); //[a, b, c, d] iterator<string> itr = vals.iterator(); while (itr.hasnext()) //a b c d { system.out.print(itr.next() + " "); } my questions: h.values() returns collection view of values in h . since vals interface, how can assign values interface (they cannot instantiated)? class implementing interface? object of class? similar question itr . know vals.iterator() returns first element of collection. how can assign interface instance? the underlying principle governs answers questions called liskov's substitution principle applies in case assign value of instance of given int