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!!
Map map = new HashMap();?HashMapinstance that can be accessed like anyMap.Iteratorinterface.Iteratorreturned byiteratormethod. This class is inner class inHashMapand is not public. Here it is.