The Artima Developer Community
Sponsored Link

Java Answers Forum
Is Iterator a Class ?

2 replies on 1 page. Most recent reply: Mar 5, 2004 10:05 AM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
anamika

Posts: 11
Nickname: anamika
Registered: Feb, 2004

Is Iterator a Class ? Posted: Feb 29, 2004 1:31 AM
Reply to this message Reply
Advertisement
Is Iterator a class?


Viswanatha Basavalingappa

Posts: 84
Nickname: viswagb
Registered: Nov, 2003

Re: Is Iterator a Class ? Posted: Mar 1, 2004 2:24 AM
Reply to this message Reply
Hi,

Iterator is NOT a class, It is a Interface.

Iterator takes the place of Enumeration in the Java collections framework.

here is the sample code.....

List contactList = obj.getContactList();
	  
Iterator contractIterator = contactList .iterator();
while(contractIterator.hasNext())
{
  ObjectmyObj= (Object)contractIterator.next();
}


Viswa
--------

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Is Iterator a Class ? Posted: Mar 5, 2004 10:05 AM
Reply to this message Reply
> Is Iterator a class?

When you compile the code for it, it produces a .class file.

But it is called an Interface.

List list = new ArrayList();
or
ArrayList list = new ArrayList();

Iterator iterator = list.iterator();
ListIterator listIterator = list.listIterator();

Check out the documentation for Iterator, ListIterator , ArrayLiist, and List:

http://java.sun.com/j2se/1.4.2/docs/api/index.html

ArrayList is a Class
List is an Interface
ListIterator is an Interface
Iterator is an Interface.

http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html#238680

http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html

Excerpt from JLS:
An interface declaration introduces a new reference type whose members are classes, interfaces, constants and abstract methods. This type has no implementation, but otherwise unrelated classes can implement it by providing implementations for its abstract methods.

A nested interface is any interface whose declaration occurs within the body of another class or interface. A top-level interface is an interface that is not a nested interface.

This chapter discusses the common semantics of all interfaces-top-level (§7.6) and nested (§8.5, §9.5). Details that are specific to particular kinds of interfaces are discussed in the sections dedicated to these constructs.

Programs can use interfaces to make it unnecessary for related classes to share a common abstract superclass or to add methods to Object. An interface may be declared to be a direct extension of one or more other interfaces, meaning that it implicitly specifies all the member types, abstract methods and constants of the interfaces it extends, except for any member types and constants that it may hide.

A class may be declared to directly implement one or more interfaces, meaning that any instance of the class implements all the abstract methods specified by the interface or interfaces. A class necessarily implements all the interfaces that its direct superclasses and direct superinterfaces do. This (multiple) interface inheritance allows objects to support (multiple) common behaviors without sharing any implementation.

A variable whose declared type is an interface type may have as its value a reference to any instance of a class which implements the specified interface. It is not sufficient that the class happen to implement all the abstract methods of the interface; the class or one of its superclasses must actually be declared to implement the interface, or else the class is not considered to implement the interface.

Flat View: This topic has 2 replies on 1 page
Topic: ejecting CD Drive Previous Topic   Next Topic Topic: Open .doc in java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use