• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Generic Collections

 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Could you please explain what's happening at line 2, 3 and 5..


 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note : Entry is the sub-interface of Map.

In Line 2, Iterator here is used for iterating the set of Map.Entry objects which gives the Collection view of "Integer" key and "String" value. So... It can iterate the eneric Map <Integer,String> EntrySet iterator.

Line 3 leads to compiler error... Since in "Iterator<Entry<Integer, String>>", "Map.Entry" is not specified...

Line 5, Iterator "Map.Entry" gives the Collection view of "Object " key and "Object" value.. When Generic Map <Integer,String> EntrySet iterator is assigned to this Iterator reference, it will lead to type mismatch error...
 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ram. If I see the source code for Entry, I see it defined in Map interface. Do you know why I cannot see in JavaDocs. One more thing is, Line 3 has NO errors.
 
Ram Narayan.M
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please check

http://download.oracle.com/javase/6/docs/api/java/util/Map.html

you can find "Map.Entry" in the JavaDoc...

And then, Line 3 has no error... Ok.... I think you have used "import static java.util.Map.Entry;"... So it will not end up in error since this kind of declaration eases to use static members without the extension of class to which they belong to
 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ram, I am looking for Entry. The link you sent has Map.Entry
 
Ram Narayan.M
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no such Outer interface called "Entry"... Ok... Is Entry used in this code a user-defined Interface?...
 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ram,

I imported import java.util.Map.Entry;

It is NOT user defined interface.
On Line 4, Entry is used i.e., Entry<Integer, String>
Iterator<Entry<Integer, String>> i2 = map.entrySet().iterator();

In the Original Map.class interface, I see the following code..Looks like Entry interface is defined in Map interface..All I want to know is to see this "Entry" interface in JavaDocs

interface Entry<K,V> {
/**
* Returns the key corresponding to this entry.
*
* @return the key corresponding to this entry
* @throws IllegalStateException implementations may, but are not
* required to, throw this exception if the entry has been
* removed from the backing map.
*/
 
Ram Narayan.M
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you have imported too detailed import java.util.Map.Entry;

You can use Entry interface without the extension "Map."... So Line2 and Line3 are both same. Thats all...
 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ram Narayan.M wrote:Since you have imported too detailed import java.util.Map.Entry;

You can use Entry interface without the extension "Map."... So Line2 and Line3 are both same. Thats all...



Hi Ram, I got your point. What I am trying to figure out is where I can see "Entry" interface in JavaDocs
 
Ram Narayan.M
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://download.oracle.com/javase/6/docs/api/java/util/Map.Entry.html

This is Entry Interface Document which contains abstract methods...
 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ram Narayan.M wrote:http://download.oracle.com/javase/6/docs/api/java/util/Map.Entry.html

This is Entry Interface Document which contains abstract methods...



This is for Map.Entry. I am looking for just Entry alone or something related to just Entry not along with Map. May be my question is dump ??
 
Ram Narayan.M
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Dude,

Since you have imported too detailed import java.util.Map.Entry;

You can use Entry interface without the extension "Map."...

I am again insisting you that there is no outer Entry interface not related to Map
 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ram Narayan.M wrote:Hey Dude,

Since you have imported too detailed import java.util.Map.Entry;

You can use Entry interface without the extension "Map."...

I am again insisting you that there is no outer Entry interface not related to Map



Hi Ram,

I am not asking on how to use Entry (or) Map.Entry.
I think I got the answer ..Maybe For inner classes/interfaces Sun/Oracle will not provide any documentation.
 
Beware the other head of science - it bites! Nibble on this message:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic