Skip to main content

Posts

Showing posts with the label iterator

Is there any Relation between Iterator.hasNext and for-each loop

I was using JProfiler for profiling of my application, as it is a huge application so I am very aware of its performance and efficiency. It was taking too long so I replace all Iterator.hasNext with for-each but when I am seeing in the JProfilers CPU view it is showing me Iterator.hasNext method called where I am using for-each . Why does so? Is there any relation between these two? Here is the example code : List<Map<String, Object>> mapList = jdbcTemplate .queryForList(MAP.SELECT_ALL); for (Map<String, Object> map : mapList) { list.add(fillPreferenceMaster(preferenceMasterMap)); }