I have a very basic question in mind. An Iterator is an interface so to create an object we will need to create a class that implements Iterator and then create an object for the same. But when i saw the use of iterator it confused me as we are referencing an interface directly without having a class that implements it. for example :
HashMap map = new HashMap();
map.put("1", "One");
map.put("2", "Two");
Iterator i = map.entrySet().iterator();
how come we have an object of an Interface!!
Iterator is a interface, but
map.entrySet().iterator()returns an object which implements the Iterator interface.