java - How to iterate HashMap without entrySet -


in original java source, must use entryset iterate hashmap, instance:

 (map.entry<string, string> e : new hash<string, string>().entryset()) {  } 

i expect more simple way iterate hashmap following:

package ro.ex;  import java.util.hashmap; import java.util.map;  /**  * created roroco on 11/17/14.  */  class hash<k, v> extends hashmap<k, v> {     // how implement? }  public class ex2 {     public static void main(string[] args) {         // expect          (hash.entry<string, string > e : new hash<string, string>()) {         }     } } 

my question is how implement it?

implement iterable<map.entry<k, v>>:

class hash<k, v> extends hashmap<k, v> implements iterable<map.entry<k, v>> {     @override     public iterator<entry<k, v>> iterator() {         return entryset().iterator();     } } 

this works because implementing iterable allows type used in for-each loop.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -