How do I get a keyIterator for a LinkedHashMap?

前端 未结 3 1143
误落风尘
误落风尘 2021-02-13 09:43

By looking at the source code for LinkedHashMaps from Sun, I see that there is a private class called KeyIterator, I would like to use this. How can I gain access?

3条回答
  •  野性不改
    2021-02-13 10:39

    It's a private class, so you can't directly use it.

      private class KeyIterator extends LinkedHashIterator {
    

    An instance of it is returned when you use the normal Iterator.

    myMap.keySet().iterator()
    

提交回复
热议问题