Iterator Interface. A question?

I am unable to grasp the meaning of the following below :
As we all know,Interfaces have abstract methods,(ie methods that
have no body) and any class that implements the Interface has to
implement the methods defined in the interface.That is,write the body for those methods.
So far so good.
Now coming to Collections called Vector.
We have the 'Iterator' interface implemented by the vector class.
The Iterator interface has the methods hasNext(),next().
and we have the following code in the our class which iterates thru'
the vector:
MyClass item;
while(iter.hasNext())
item = (MyClass)iter.next();
// Do something here.....
We are using the methods hasNext() and next() above.
But as they belong to the Iterator interface,(which means they
are basically methods with no implementations) then how is iteration
possible? We havent defined anything in the hasNext() method or the next()
so how does Java automatically start iteration
Has any one understood my question?Arent hasNext() and next() supposed
to be methods with no body?.
Arent they supposed to be empty()?
If they have no body,then how are they being implemented?
If I am saying iter.hasNext(),that means hasNext() has been defined
somewhere to iterate thru the vector?
I am just confused regarding this issue as to how is hasNext() and next()
being implemented as I as the programmer have not implemented them
in my code
Please can some one answer my question?
Regards
Ajay

public Iterator iterator()
Returns an iterator over the elements in this list in proper sequence.
This implementation returns a straightforward implementation of the iterator interface, relying on the backing list's size(), get(int), and remove(int) methods.
Note that the iterator returned by this method will throw an UnsupportedOperationException in response to its remove method unless the list's remove(int) method is overridden.
This implementation can be made to throw runtime exceptions in the face of concurrent modification, as described in the specification for the (protected) modCount field.
Specified by:
iterator in interface List
Specified by:
iterator in class AbstractCollection
Returns:
an iterator over the elements in this list in proper sequence.
See Also:
modCount
So based on the above JavaDoc for java.util.AbstractList, which Vector sub-classes, the iterator() method returns an implementaion of the iterator interface. This is where the methods are defined.

Similar Messages

  • Iterator Interface.A question please.

    I am unable to grasp the meaning of the following below :
    As we all know,Interfaces have abstract methods,(ie methods that
    have no body) and any class that implements the Interface has to
    implement the methods defined in the interface.That is,write the body for those methods.
    So far so good.
    Now coming to Collections called Vector.
    We have the 'Iterator' interface implemented by the vector class.
    The Iterator interface has the methods hasNext(),next().
    and we have the following code in the our class which iterates thru'
    the vector:
    MyClass item;
    while(iter.hasNext())
    item = (MyClass)iter.next();
    // Do something here.....
    Now we are using the methods hasNext() and next() above.
    But as they belong to the Iterator interface,(which means they
    are basically methods with no implementations) then how is iteration
    possible? We havent defined anything in the hasNext() method or the next()
    so how does Java automatically start iteration
    Has any one understood my question?Arent hasNext() and next() supposed
    to be methods with no body???
    If I am saying iter.hasNext(),that means hasNext() has been defined
    somewhere to iterate thru the vector?
    I am just confused regarding this issue as to how is hasNext() and next()
    being implemented as I as the programmer have not implemented them
    in my code
    Please can some one answer my question?
    Regards
    Ajay

    Thanks Will.
    Regarding the question,then why define an Iterator interface when
    the collection class implements the functionality?
    Why not define the methods hasNext() and next() in the Object
    class?
    So by default,all classes extends the Object class ,we
    cud use the hasNext() and next() method?
    No??? Or am I wrong?

  • Iterator Interface.A question please......respond

    I am unable to grasp the meaning of the following below :
    As we all know,Interfaces have abstract methods,(ie methods that
    have no body) and any class that implements the Interface has to
    implement the methods defined in the interface.That is,write the body for those methods.
    So far so good.
    Now coming to Collections called Vector.
    We have the 'Iterator' interface implemented by the vector class.
    The Iterator interface has the methods hasNext(),next().
    and we have the following code in the our class which iterates thru'
    the vector:
    MyClass item;
    while(iter.hasNext())
    item = (MyClass)iter.next();
    // Do something here.....
    Now we are using the methods hasNext() and next() above.
    But as they belong to the Iterator interface,(which means they
    are basically methods with no implementations) then how is iteration
    possible? We havent defined anything in the hasNext() method or the next()
    so how does Java automatically start iteration
    Has any one understood my question?Arent hasNext() and next() supposed
    to be methods with no body???
    If I am saying iter.hasNext(),that means hasNext() has been defined
    somewhere to iterate thru the vector?
    I am just confused regarding this issue as to how is hasNext() and next()
    being implemented as I as the programmer have not implemented them
    in my code
    Please can some one answer my question?
    Regards
    Ajay

    Thanks for yr reply.
    So you mean to say the the Iterator methods hasNext()
    and next()
    are being implemented by the Vector class.right?Not exactly. The Vector class defines an inner class, and it is this class that implements the Iterator interface, and so these two methods. When you write code like
    Vector myVector = new Vector();
    // code to fill myVector...
    Iterator it = myVector.iterator();the call to the iterator() method tells myVector to give you an instance of this inner class. The Vector class itself doesn't implement next() or hasNext().
    Then why define an interface with these methods at
    all?
    Why not give concrete bodies to these methods and put
    them in
    the Object Class.If you did that, then all classes would inherit them - all classes would be iterators. That wouldn't make sense, though, as clearly not all classes are meant to be used to iterate over collections of objects.
    Iterator is an interface so that a consistent API can be defined for iteration. As iterators are used in lots of different places, it is very helpful to have all of them guaranteed to have next() and hasNext() methods (amongst others). It is also very helpful to be able to call the iterator() method on any Collection class and know that the object that is returned, regardless of its implementation, will be of type Iterator.
    Then we can call them polymorphically.???But that's what you're doing - Vector and ArrayList (for example) have different implementations of Iterator, but code that iterates over them doesn't need to know that. As both return objects that implement the Iterator interface, they are interchangeable; that's polymorphism at work.

  • Implementing Iterable interface

    Just trying to implement the the Iterable<> interface into my Stack class ... as far as I can tell I cannot specify a type beyond Object when iterating through it using the ForEach loop structure. Any thoughts on how to correct this or is my design limited?
    * @(#)Queue.java
    * @Matthew Cox
    * @version 1.00 2009/2/11
    import java.util.*;
    public class Stack<T> implements Iterable<T>
         private LinkedList<T> list;
         private int size;
        public Stack()
             list = new LinkedList<T>();
             size = 0;
        public void push(T node)
             if (node != null)
                  list.addFirst(node);
                  size++;
             else
                  System.out.println("Cannot push null value onto stack.");
        public T pop()
             T removedNode = null;
             if (!isEmpty())
                  removedNode = list.removeFirst();
             else
                  System.out.println("Stack is empty.");
             return(removedNode);
        public T[] toArray()
             return((T[]) list.toArray());
        public boolean isEmpty()
             return(size == 0);
        public boolean equals(LinkedList vList)
             return(list.equals(vList));
        public Iterator<T> iterator()
             return(list.iterator());
        public static void main(String[] args)
             Stack s1 = new Stack<Integer>();
             for (int count=0; count< 10; count++)
                  s1.push(new Integer(count)); //(int)(Math.random()*16+0)
             for(Object i : s1) //RIGHT HERE, I want to be able to say "Integer i : s1" but I get an incompatible types error
                  System.out.println(i);
    }I don't really understand why I would be getting the error stating the the type being sent back is Object ... my Iterator() method returns an iterator of type T not type Object from how I understood it... any thoughts?

    // Stack  s1 = new Stack<Integer>(); // this loses the type information
    Stack <Integer> s1 = new Stack<Integer>();

  • Any example of FOR UPDATE iterator interface?

    Hi,
    did play somebody with iterator with ForUpdate interface? I really appreciate any example of that. I am sorry, I did not find anything in documentation, just definition of interface in reference.
    Radek
    null

    Oracle SQLJ currently does not support the ForUpdate functionality - that's why you did not see any further mention in the documentation.
    Though you can define iterators that implement the ForUpdate interface and write UPDATE/DELETE statements (UPDATE ... WHERE CURRENT OF :forUpdateIterator), you will receive an error during the profile customization that positioned updates are not supported.
    In Oracle the workaround is to also select out a ROWID column in queries for update and then use WHERE rowid = :(iter.rowid()) instead of WHERE CURRENT OF :iter.
    (One of these days, when SQLJ supports WHERE CURRENT OF, this would actually be what we'd do in an implementation of this feature.)

  • HSRP Interface Tracking Question

    I have a pair of 7206 routers for Internet access.  The Internet was provided over OC3, and used interface POS1/0.  I just upgraded the Internet to Ethernet so now the interface is GigabitEthernet 0/3.
    I just discovered that there there is another interface that uses POS1/0 as an HSRP tracking interface.  So my question is:   Can I just remove the old tracking interface and add the new one? Or is there another prefered method to do this?
    My current HSRP interface:
    interface GigabitEthernet0/1.21
     description INET
     encapsulation dot1Q 21
     ip address x.x.x.x 255.255.255.240
     ip broadcast-address x.x.x.x
     no ip redirects
     ip accounting output-packets
     ip flow ingress
     ip nbar protocol-discovery
     no snmp trap link-status
     standby 1 ip x.x.x.x
     standby 1 priority 105
     standby 1 preempt
     standby 1 track POS1/0
    Thanks!
    Ray

    Ray
    While it is correct that you can just change the HRP interface to track the Ethernet interface be aware that it may not work quite the same way. With POS and most serial interface implementations if communications with the peer is lost then the loss of keepalives will change the interface state to line protocol down and that is what the interface tracking is looking for. However with an Ethernet interface if you lose communication with the peer the interface may still be in a line protocol up state. In that circumstance interface tracking will not detect the problem.
    HTH
    Rick

  • Relational interface, basic question

    Hi, I have over a million images stored in a blob column.
    We are using oracle 8.1.7 and forms 6.0.
    We do have intermedia installed on the database but it is not
    used in this application.
    The images were inserted as TIFF's through a form.
    Question.
    Intermedia Relational interface be used to change the
    compression setting of the TIFF images? using the process()
    method?
    Can Intermedia Relational interface be used to change the image
    format of some of the images?
    Thank you
    David Wilton

    Rajiv,
    I like your suggestion of using the process method from a stored
    procedure without having to install intermedia relational
    interface. I'm not sure how to assign the ORDSYS variables to
    the blob. David, please see the example below.
    Our problem:
    We have some TIFF images compression: CCITT group 3 and 4
    (lossless compression).
    Some of these images cause the forms application to crash upon
    display. Forms bug, oracle sent me an oneoff for patch 9 for
    forms 6i to see if this corrects the problem, it did not.
    Using Forms, If I update the record and resave the image as
    image type JFIF, the image can be viewed without problems.
    I think when the image is saved as a JPEG some of the discarded
    information might be what causes the image to crash the oracle
    forms application. Therefore it no longer crashes the
    application.
    I am wondering if I can change the compression settings of these
    problem images to JPEG and keep the image as a TIFF. or change
    to a JPEG image and jpeg compression save then possibly convert
    it back to TIFF.
    David, if I understand your scenario correctly, your client
    application is having a problem displaying certain TIFF images.
    You want to modify these (by changing compression/deleting tags
    etc) so that your client can display them correctly.
    You should try changing the compression of these images from
    CCITT 3/4 to PackBits or LZW first before trying JPEG.
    In your case, using JPEG compression will explode the size of
    the image data (CCITT is monochrome whereas JPEG will use 8bits)
    and the image quality will also deteriorate.
    If on the other hand I misunderstood your scenario and you are
    having a problem with our TIFF reader with certain images, please
    send us a sample problem file to investigate this further.
    Here's the start of my procedure
    how do I assign the ordsys variables to my blob?
    thank you
    David
    PROCEDURE change_image IS
    v_image BLOB;
    v_intermed_image ORDSYS.ORDImage;
    v_blob_intermed ORDSYS.ORDImgB;
    BEGIN
    select image_data
    --into v_blob_intermed
    into v_image
    from obra.scanned_images
    where scanned_images_rec = 1218450
    for update;
    -- how to assign ordsys variable to blob????
    v_intermed_image := v_image;
    -- v_blob_intermed := v_image;
    -- keep tiff format change compression from group 3 to jpeg
    ordsys.ordimage.process
    (v_intermed_image, 'compressionFormat=JPEG,compressionQuality=MED
    COMP');
    -- change image to jpeg format
    -- ordsys.ordimage.process
    (v_intermed_image, 'fileFormat=JFIF,
    compressionFormat=JPEG,compressionQuality=MEDCOMP');
    update obra.scanned_images
    set image_data = v_intermed_image
    where scanned_images_rec = 1218450;
    commit;
    exception
         when others then
         raise;
    END; PROCEDURE change_image IS
    v_intermed_image ORDSYS.ORDImage;
    BEGIN
    select image_data
    into v_intermed_image.source.localdata
    from obra.scanned_images
    where scanned_images_rec = 1218450
    for update;
    -- you can optionally invoke setProperties to inspect the image
    -- v_intermed_image.setProperties ;
    -- dbms_output.put_line('Height ' ||v_intermed_image.height);
    -- keep tiff format change compression from group 3 to packbits
    v_intermed_image.process( 'compressionFormat=PACKBITS,
    compressionQuality=MEDCOMP');
    -- for blobs selected for update, you don't need an additional
    -- update but it doesn't hurt. If you were updating a lob
    -- attribute of an object you would need the line below.
    update obra.scanned_images
    set image_data = v_intermed_image.source.localdata
    where scanned_images_rec = 1218450;
    commit;
    exception
    when others then
    raise;
    END;

  • Webdav - user management - web interface - some questions

    Hi,
    after browsing several hours to find any answer to my questions regarding webdav and lion server unsuccessfully i decided to raise theses questions collected here in this forum.
    1. Is there a web interface for the webdav folder coming along with lion server? If no, where can i get one
         (similiar to e.g. idisk within mobile me)
    2. how do i setup user for webdav. My users which i setup within the server app didn't work
    3. is this (http://gigaom.com/apple/how-to-enable-webdav-on-your-mac-for-iwork-on-ipad/) the only way to setup user for webdav? how can i use the users which i setup for webdav?
    thanks in advance
    cheers
    tobi

    You can set up a "share" (or point to an already created one) that enables Webdav for IOS devices in Server app.  For example:  we have 260 students that have their "home" directories listed at /Student_home.  Go into Server app, select file sharing and choose the "share" that you want to enable webdav.  Click the edit pencil and under Settings select Share with IOS devices (webdav).  Then on your device use the URL http://your.server.com/webdav/short_user_name.  If you have SSL turned on for web, you'll need https.  Authenticate with the short name and password of user.  This works with iPad, iPhone, Macs and Windows Desktops (windows you'll need to Map a network drive).
    So Johnny Brown grabs his iPad with Pages, says get document from Webdav and is presented with the login:  Enters https://myserver.com/webdav/johnnybrown for the server,  johnnybrown for username and whatever for password.
    You could also make a share for a group "dropbox" to share documents and such.  Lots of possibilities.
    I haven't messed around with the profile manager but I believe that PM will attempt to control this for each device registered to each user.  If so, you'll have to enable sharing with trusted certificates in the PM.  Since we're using this in an educational environment and don't have enough iPads, the students have to share which means that we can't assign one device per individual.
    Hope this helps
    Nathan

  • Firewire audio interface comparison question

    hello, i been comparing interfaces and have a few questions. some of them are 24bit/96khz and some are 24bit/192khz. im looking at 2 brands in my budget.
    http://www.musiciansfriend.com/product/PreSonus-Firestudio-26x26-Firewire-Record ing-System?sku=241848
    http://www.musiciansfriend.com/product/Focusrite-Saffire-Pro-26-IO?sku=241135
    because im new to recording im not sure i would even hear the difference between the 96khz and 192khz. big numbers looks better on paper but i could be wrong. im hoping someone may have compared these already and have info for me to guide my purchase. thanks for any help

    They can take advantage of the higher sample rates
    Can you hear a difference? I could probably find a dozen web pages that say it's possible and another that say it's not.
    I would use the highest sample rate I could, but I would not base a buying decision on 96k vs. 192k unless the other features I were interested were identical.
    Recording, Mixing, and Mastering technique can trump hardware.
    As an example, go here:
    http://www.bulletsandbones.com/BBPages/History/History.html
    and listen to the Real World sample, and then the Shine sample. One was recorded with a $30 interface, the other with an (at the time) $800 interface.

  • Lexicon Lambda Audio Interface - newbie question

    OK, not strictly a Logic Express question, but I am using a Lexicon lambda audio interface with LE.
    I'm new to audio interfaces, having just bought my second synth, so I needed an interface in order to connect both synths to the Mac.
    Both synths are stereo (2 quarter-inch outputs), and having played around with the Lexicon I'm forming the opinion that I actually need a 4-input interface, rather than a 2-input, in order to connect both synths in stereo. I was hoping I could use an adapter on the two quarter-inch plugs to convert to a single quarter-inch stereo but I still only get sound through one channel.
    Can someone confirm that it is actually a 4-input interface I need?
    Thanks in advance.

    Hi.
    I 've had a lexicon omega for a while and have tried it in a macbook (osx 10.5) and a mac mini (osx 10.6.2).
    The interface works wonderfully for about 10mins and then it stops processing the playback signal. I can only hear sound on the direct.
    I've returned the interface to the vendor and they say it's fine. I've contacted lexicon support and they responded: "If the clipping is only heard when the Monitor Mix knob is set to Playback, this may be a problem with your Mac's Core Audio. In this case you may want to contact Apple or try reinstalling the OS".
    Since I've tried with 2 different Mac machines, and with different osx versions, i think I can rule out trying to "reinstall the OS".
    Do you guys have any idea how I can mend this?
    It has become really frustrating...
    Thanks

  • 3550 Switch -Fiber interface VLAN question

    Hello,
    I will deploying two Cisco 3550 Switches and connecting them via a ordinary multimode fiber with GBIC 1000BASE-SX - transceivers installed on each switch. Here is my question: I will be configureing about half of the ports on each of the switches to be in one of two VLANS. I would like to configure the two vlans to run over the single fiber line. Is is possible to configure one fiber port, with the GBIC 1000BASE-SX - transceiver installed, with two vlans and/or subinterfaces each with half of the 1000mb of bandwidth, or will I need to run an additional fiber line connected to the second fiber interface on the 3550 to accomplish this. I really hope not to as I don't have the funds to run a second line at this time. If this configuration is possible could someone please point me to documentation on how to configure this and\or give some advice. Thank you.
    Regards,
    JPS

    Just set up the link as a trunk , this allows you to send as many vlans across that link as you want . On each side just do the following.
    switchport
    switchport trunk encapsulation dot1q
    switchport trunk mode dynamic desirable
    Verify trunk status with the "show int trunk " command.
    More info at http://www.cisco.com/en/US/products/hw/switches/ps5528/products_configuration_guide_chapter09186a00803a9af5.html#wp1200245

  • What would you do? Interface/HD question

    This post is similar to others made before but they have not covered my exact question. Anyway,
    I use an ibook g4 with an edirol firewire interface (10 channel). I need more hard disk space so i would like to get an external hard drive. Do you suggest i get:
    1) A usb 2.0 hard drive
    2) A firewire hard drive, daisy chained to the firewire interface.
    If so what should i look for in terms of specs?
    I do normal sized recordings (bands) so not too many tracks, however i tend to use a lot of reverbs and compressors etc.
    Specific brands/models would be good too. Cheers

    Considering that USB2.0 is a bit faster than firewire, there is a chance that it may work, but to be honest, you would have to try it to see if a USB2.0 drive could carry a heavy load of data back and forth. Of course, if your iBook doesn't have USB2.0 (the latest ones do), then I wouldn't even consider USB in that case.
    jord

  • Iterator interface, how to implement?

    Hi,
    I'm working on an assignment, but I can't really understand one thing. In the following few lines I'll try to describe the situation.
    I have a class which has a TreeMap of Objects. These Objects have there own variables etc... and are comparable.
    Now I need to implement an interface which makes it possible to iterate over the objects in the TreeMap.
    And I need to add some functions like:
    getCurrent() (where does the pointer stands at this moment)
    getNbElements() (how many elements are there after the current position of the pointer)
    advance() (put the pointer one position further, like next() but without the return)
    reset() (put the pointer back at the first element)
    I have no idea how to implement this, do I need to create a seperate class which is the iterator ?
    I hope someone can clear some things up, I don't need a solution, just a way of thinking.
    Thanks in advance.

    Shyamisuga wrote:
    S. U can do all tat by implementing method for each of ur function., instead my suggestion would be to use Arraylist in this case, as they hav all these functions implemented, u just gotto cal them, makes life lot simpler.. :)Awesome advice. He can implement them by implementing them. I thank the gods you're not a pathologist
    "Lassa fever? Ah, that's easy to cure. Simply cure it, and it'll be cured"

  • FPGA Interface Cast question

    I'm playing with a 5644 VST and the VST Streaming template.  On the FPGA VI I added some code, then added an indicator to the FPGA VI front panel and compiled.  Running the FPGA VI in interactive execution mode, the indicator works well.  On the host end, though, I can't seem to access the new indicator with a Read/Write control. 
    Coming out of the Open FPGA VI Reference I can see the indicator on the wire, but in the Dynamic FPGA Interface Cast function it's getting stripped out of the refnum somehow.  If I connect a Read/Write control directly to the output of the Open Reference function I can access the indicator just fine.
    Any idea what I'm doing wrong?
    Thanks.
    Solved!
    Go to Solution.

    Have you re-configured your FPGA VI reference interface with the new bitfile?  The dynamic interface cast defines the output wire as having all the methods and indicators described by the type wire connected.  You can right-click on the type constant and select "Configure FPGA VI Reference...".  In the pop-up that follows, choose "Import from bitfile..." and then select the new bitfile that you've built.
    You'll need to update the fpga reference type in the "Device Session.ctl" type def as well.  This is the type that you'll be able to access throughout the project.

  • Web Interface Assistance/Question - General

    I would like to develop a web interface that I can embed in my netbeans created app. However, I do not know where to start. Here is would I would like to do:
    connect to a specific url
    Retreive the URL screen
    locate two fields used on the screen and send ("User/Password") back
    wait for next window to appear and retrieve it.
    locate a button on the form and send an activation back to the host.
    I know this sounds like a "Why do this?". This is just a learning exercies for me.
    Can anyone provide me a to somthing I can study/read about this type of development?
    If anyone has a small sample code, and you can point me to it, this would help?

    Wrong posting

Maybe you are looking for