Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replace map for-each by classic for-loop?

Java 8

here some snippet:

String createSelector(Map.Entry<String, Map<String, String>> seriesMapEntry) {
   for (Map.Entry<String,String> column : seriesMapEntry.getValue().entrySet()) {
        String expr = column.getValue();
         // some code here
   }
}

Nice. It’s work fine.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is it possible to iterate seriesMapEntry without for-each loop? E.g use classic for loop (iterate by index).

>Solution :

There is no index to iterate over. You can, however, use an explicit Iterator and a while loop:

String createSelector(Map.Entry<String, Map<String, String>> seriesMapEntry) {
   Iterator<Map.Entry<String,String>> iter = seriesMapEntry.getValue().entrySet().iterator();
   while (iter.hasNext ()) {
        Map.Entry<String,String> column = iter.next ();
        String expr = column.getValue();
         // some code here
   }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading