Reasons why to use Iterator for List rather than for loop ?

when i use the iterator and for loop for traversing through the list. it takes the same time for iterator and also for for loop. even if there is a change it is a minor millisecond difference.
what is the actual difference and what is happening behind the traversing list through iterator
if we are using we are importing extra classes ...if we are using for loop there is no need to import any classes

If you have an array-backed collection, like an ArrayList, then the difference between using an iterator and get() will be negligible.
However, if you have a linked list, using get() is O(n^2) whereas iterator is O(n).
So with an iterator, regardless of what your underlying data structure, a list of 100,000 elements takes 1,000 times as long to iterate over as a list with 100 elements. But using get() on a LinkedList, that same 100,000 element list will take 1,000,000 times as long as the 100 item list.
There's no real benefit to ever using get()
Side note: I've been comparing iterators to get(), not iterators to for loops. This is because whether it's a for or a while has nothing to do with whether you use an iterator or get(). The way I use iterators is for (Iterator iter = list.iterator(); iter.hasNext(); ) {
    Foo foo = (Foo)iter.next();
}

Similar Messages

  • Why not use interfaces for constants?

    Hi,
    I have been getting conflicting views about why not use interfaces for constants?
    Can anyone shed some light on it?
    Piyush

    How so?
    If the constants are only used in a single classhow
    does it help to put them in a separate structute?
    (Ignoring the a type safe enumeration of course.)Well, mainly for readability. Suppose that you have a
    web application which has a servlet class
    "RedirectServlet", which takes a variable to redirect
    to a given JSP file. In the JSP files, you want to
    create forms which take this servlet as their action.
    You could of course put all these "redirect"
    constants in the RedirectServlet itself, but then
    it's kind of weird that you have to import a
    servlet in your jsp file to include these constants
    and to be able to write
    <form action="servlet/RedirectServlet?key=<%=
    RedirectServlet.HOMEPAGE %>> or so.
    Instead, you could create an interface called
    "RedirectConstants", and then your servlet
    RedirectServlet could implement this interface. Then
    your JSP can also access these constants via this
    interface.
    But then again, this is merely a matter of style, I
    fully agree that there is never a real _need_ to put
    constants in a separate structure if they're only used
    in a single class.Are you claiming that your example above is a single class?

  • [svn:fx-trunk] 12552: DataGroup now tracks the indices of the active virtual item renderers with a list , rather than the min/max values.

    Revision: 12552
    Revision: 12552
    Author:   [email protected]
    Date:     2009-12-04 13:45:12 -0800 (Fri, 04 Dec 2009)
    Log Message:
    DataGroup now tracks the indices of the active virtual item renderers with a list, rather than the min/max values. 
    DataGroup/addItemRendererToDisplayList() now respects the overlay.
    QE notes:
    Doc notes:
    Bugs: sdk-24052
    Reviewer:
    Tests run: DataGroup, List
    Is noteworthy for integration: no
    Ticket Links:
        http://bugs.adobe.com/jira/browse/sdk-24052
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/DataGroup.as

    Hello Martin:
    Thanks for your input.  However I am not certain we have resolved this issue adequately, or understand the principles governing the css as regards this spry menu framework 2.0 (1.0).
    For example, the menu only works in IE 6.0 if the css remains in the head.  I agree with your original post that it shouldn't make any difference whether the css is posted in the head or in a separate style sheet (so long as specificity issues are addressed).  Both should work -- and yet it doesn't.
    If the CSS is placed in the separate style sheet governing the total site, it doesn't work for 6.0.  If placed at the top of the style sheet, conflicts of specificity prevent the menu from rendering properly in any of the browsers causing the rules for general links to govern the menu.   This has been verified using a cross browser testing.  If the styles are placed at the bottom of the style sheet to help them take precedence, they work in all the browsers except for IE 6.
    The website I am building needs to support IE 6 for a variety of reasons, and because it is catering to the non-profit community and to low income persons, I am mindful of even small differences in page weight.
    So for me, at least, the issue remains baffling.
    I appreciate your input, but also would appreciate the input from others, and especially Adobe Community Professionals and employees.  The spry framework in this regard is not well documented.  I am not certain if this is exclusively a CSS problem, if it might also be complicated by the architecture of the spry framework, or if indeed other variables are at play.
    I would be my hope that in resolving the problem, other users of the this particular spry framework might also benefit.
    Thanks,
    Steve.

  • How can I use "t3://becluster:6001" rather than "t3://dcsv02,dcsv01:6001"

              I have 2 machines in a cluster (dcsv01 and dcsv02) (HP UNIX with weblogic server
              5.1 sp8) and 1 Windows PC with weblogic 5.1 sp10.
              I try to make a t3 connection between the PC and the cluster of machines.
              On the Windows PC I have the following configuration for the
              "c:\windows\system32\drivers\etc\Hosts" :
              171.1.70.61     becluster
              171.1.70.62     becluster
              where
              "171.1.70.61 is dcsv01 and
              171.1.70.62 is dcsv02 "
              If I connect my PC to the cluster with :
              hp.put(Context.PROVIDER_URL, "t3://dcsv01, dcsv02:6001"); :
              I have a great failover mechanism : if any of the machine (dcsv01 or dcsv02) are
              down the requests are routed to the other one.
              BUT!! If I connect my PC to the cluster with :
              hp.put(Context.PROVIDER_URL, "t3://becluster:6001"); :
              I have a not great failover mechanism :
              say that my windows hosts file looks like :
              171.1.70.61(dcsv01)     becluster
              171.1.70.62(dcsv02)     becluster
              then if dcsv02 is down then all requests are routed to dcsv01 and that is fine.
              BUT!! if dcsv01 is down then I got on my PC the
              "Bootstrap unable to get a t3 connection to dcsv01" exception and failover does
              not work. (not the way that it does with t3://dcsv01, dcsv02:6001 )
              So how can I use
              "t3://beclsuter:6001" rather than
              "t3://dcsv01, dcsv02:6001" with the same failover service????
              Thanks
              

              Thanks mike,
              In a UNIX or windows environment how can I get a DNS server that round robin?
              "Michael Reiche" <[email protected]> wrote:
              >You need to have becluster defined in a DNS that round-robins.
              >
              >Mike
              >
              >"Martial" <[email protected]> wrote in message
              >news:[email protected]...
              >>
              >> I have 2 machines in a cluster (dcsv01 and dcsv02) (HP UNIX with weblogic
              >server
              >> 5.1 sp8) and 1 Windows PC with weblogic 5.1 sp10.
              >>
              >> I try to make a t3 connection between the PC and the cluster of machines.
              >>
              >> On the Windows PC I have the following configuration for the
              >> "c:\windows\system32\drivers\etc\Hosts" :
              >> 171.1.70.61 becluster
              >> 171.1.70.62 becluster
              >> where
              >> "171.1.70.61 is dcsv01 and
              >> 171.1.70.62 is dcsv02 "
              >>
              >> If I connect my PC to the cluster with :
              >> hp.put(Context.PROVIDER_URL, "t3://dcsv01, dcsv02:6001"); :
              >> I have a great failover mechanism : if any of the machine (dcsv01 or
              >dcsv02) are
              >> down the requests are routed to the other one.
              >>
              >> BUT!! If I connect my PC to the cluster with :
              >> hp.put(Context.PROVIDER_URL, "t3://becluster:6001"); :
              >> I have a not great failover mechanism :
              >> say that my windows hosts file looks like :
              >> ..
              >> 171.1.70.61(dcsv01) becluster
              >> 171.1.70.62(dcsv02) becluster
              >> ..
              >> then if dcsv02 is down then all requests are routed to dcsv01 and that
              >is
              >fine.
              >> BUT!! if dcsv01 is down then I got on my PC the
              >> "Bootstrap unable to get a t3 connection to dcsv01" exception and failover
              >does
              >> not work. (not the way that it does with t3://dcsv01, dcsv02:6001 )
              >> So how can I use
              >> "t3://beclsuter:6001" rather than
              >> "t3://dcsv01, dcsv02:6001" with the same failover service????
              >>
              >> Thanks
              >>
              >>
              >>
              >
              >
              

  • It opens into my recent calls list rather than the home screen

    Every time I receive a call when my phone is 'asleep' the phone goes back to sleep state when the call is hung up. As it should.
    Weirdness is though…when I next wake the phone it always opens straight into my recent calls list, rather than the home screen.
    It only happens on incoming calls, and only when the call is received while the phone's asleep.
    I've done a restore (for something else) but it didn't remedy this.
    Anyone else seeing the same?

    Sure about what? That there is nothing wrong with your phone or that the OS works that way...the answer is yes to both questions. Works the same if you go into settings but let the phone go to sleep, next time you unlock your phone, you'll be in settings. If you don't want your phone to do that, hit the home button after a call.

  • Using a For Loop Index for Array Element Number?

    Hi.  Thanks in advance for the help.  I can't seem to find what I want to do here using the search function... probably because I don't know how to frame the question appropriately.  Ignore the title to this post cause it's probably wrong vocabulary for what I want to do.
    Here's the situation:
    I have a 2D array where the first column is the X data and each subsequent column is Y data (call it Y1...Yn).  The n-value varies from run to run (some runs have 4 columns of data, some have 20), but that is easily gathered when reading the data file.  I need to perform a number of operations on each set of data, the least of which is smoothing the data and graphing it, so I'm limiting my discussion to these 2 operations.
    What I want is a for loop structure where the indexing of the loop tracks the Y1...Yn columns, grabs each column for the iteration, performs the relevant analysis, and spits out the result, but in a stackable manner.  Thus the title; I want to use the for loop's index to mark the array element for building a new array.
    See the image attached.  A 2D array of 9 columns (X, Y1...Y8) is analyzed such that each data set, (X, Y1), (X, Y2)...(X, Y8) is bundled, graphed, run through a B-spline Fit, of which is also graphed.  I need to replace this with something that looks like the for loop structure shown.  
    I just don't know how to get those two data bundles [(X, Yi) and it's smoothed pair] out of the for loop in a stacked set from every iteration of the for loop.
    Again the title, I think I want to build a new array where i use the index of the for loop to control the entries of the new array.  But I can't see how to do that.
    Any help would be appreciated.
    Attachments:
    NeedForLoopForThis.PNG ‏30 KB

    Hello H.R. Dunham, and welcome to the forum!
    It seems that you may be looking for Auto-Indexing, a basic feature of loops in LabVIEW.  You'll need to transpose your array before wiring it into the for loop, as elements are auto-indexed by row before column, but at that point you should be able to operate on each column and output an array of n cluster elements corresponding to your input columns.  Auto-indexing tunnels look like brackets to indicate each element will be indexed automatically- this should be the default when wiring an array into a for loop or when wiring anything out of a for loop.
    As for how to build your pairs, I suggest removing the X column and creating a "starter" cluster containing your X data and placeholder Y data before entering your "Y" processing loop.  Use the bundle by name function in the for loop to insert your processed column data into the cluster and auto-index the cluster output. Flow would be something like this:
    1) Gather data
    2) Split X and Y using standard array operations
    3) Create "template" cluster with shared X data
    4) Pass template cluster and Y-column array into an auto-indexed for loop.
    5) Insert processed Y data into cluster inside loop.
    6) Auto-index cluster data out of loop.
    This tutorial is probably also a good place to get started:
    Getting Started with NI LabVIEW Module 3: Loops
    http://www.ni.com/white-paper/7528/en/
    Hope that helps!
    Regards,
    Tom L.

  • Zero iteration for loop

    Hi folks,
    There's an old behavior that I'm pretty used to, but it still occasionally bites me (usually with references).  It happened again today, and it got me to wondering if it's really intended behavior.
    If you pass a value into a zero iteration for loop, then send it out the other side, the value exiting the for loop is returned to default, not the value you fed in (see simple.vi, LV7.1).
    Any ideas?
    Joe Z.
    Attachments:
    simple.vi ‏11 KB

    This is expected behavior...the workaround is to use shift registers to pass the value through instead of tunnels.  I believe this is discussed in the LabVIEW Help.
    -D
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • Using a For loop to call one array element at a time

    I have been working on a VI that reads a GPS unit, parses the data, outputs what I need, compares the actual GPS location to the desired location, determines a desired heading and moves on from there.  My question pertains to the number of desired locations I can input right now.  I need to be able to input a predtermined number of locations (not just the one that I can input right now).  I was told that it is possible to use a For Loop with an array and have the first set of Lat and Long values run through the VI and when everything is complete that the next set of values will be chosen.  Does this mean that I need to put the entire VI inside a For Loop and have the array update as soon as the VI has completed its first mission?  I understand the concept of how this work from other programming languages but I'm not sure how to implement the solution in LabVIEW.  Any help would be appreciated.
    Adam

    adamoutlaw wrote:
    Here is a portion of the VI.  I need two separate arrays, one for Latitude and one for Longitude, of the same size.
    I don't see any arrays in your code. Do you want to generate arrays form individual data points or do you want to process arrays, one element at a time? Both can take advantage of autoindexing. Here's a simple picture.
    Your VI contains a weird mix of DBL and EXT precision. Most likely all you need is DBL. Keep your representations consistent!
    Message Edited by altenbach on 08-02-2007 07:14 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Indexing.png ‏4 KB

  • I am trying to sync my iPhone iMessages to my MacBook Air using my phone number rather than my email address as my messages on my phone come through to my phone number.  My husband has been able to set it up, accidentally I think, but I can't seem to.

    I am trying to sync my iPhone iMessages to my MacBook Air using my phone number rather than my email address as my messages on my phone come through to my phone number and not my email address.  My husband has been able to set it up, accidentally I think, but I can't seem to.

    how to find IMEI, etc
    http://support.apple.com/kb/HT4061?viewlocale=en_US&locale=en_US

  • Transposing data in an array using a For Loop

    I am trying to transpose some data in an array using a  for loop starting from the size of the array then decrement down to 0. Can someone please help if you have an example?
    Solved!
    Go to Solution.

    I feel as if reverse 1D array may help
    Edit: misunderstood what your second post meant.
    CLA, LabVIEW Versions 2010-2013

  • I'm creating an array using a for loop, how do I get the values outside the loop while it is running? thanks

    I'm creating a set of values using a for loop and a shift register inside the loop. I want access to these values outside the loop as they are being created inside. When I connect a wire from the shift register to a display outside, it doesn't work. How do I do this? Thank you.
    Attachments:
    tamko_new.vi ‏29 KB

    I tried to create the local variable that was wired to numeric indicator inside the loop. If I try to connect this to the analog output outside the loop, the loop just starts blinking and nothing happens, am I doing something wrong? Thanks again.
    Attachments:
    tamko_new2.vi ‏29 KB

  • Weird problem with loading data from an XML using a for loop

    Hi,
    I have a strange problem. I have encountered this thing many a times but still don't know the proper workaround for it.
    I am trying to load swf file, a video file or an image. They can be present on a local system or on a remote server also. All the entries corresponding to the files to be loaded is made in an XML file. I traverse through the nodes of the XML using a for loop. On the complete event of loader info, example:.
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    I fill a container with the loaded data.
    My problem is when I am using for loop it doesn't works properly but if i use a statement like this:
    someFunc()
         if(i<arr.length())
         ... do something...
         loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    private function onComplete(e:Event):void
    ... do something...
    i++;
    All files are loaded properly.
    I think this can be because the for loop processes pretty fast but the content takes time to load, which ultimately leads to some wierd results.
    Please let me know how can this thing be done correctly by using a for loop also.

    You don't want to use a for loop to load several items.  The way you almost appear to have it is the proper approach... load a file and use the completion of its loading to trigger loading the next file.

  • I have two options in my apple contacts. And I chose to not expose my hotmail contacts to limit the length of my list. Now whenever I add someone they get saved to my hotmail contact list, rather than iCloud. How do I change this?

    I have two options in my apple contacts. And I chose to not expose my hotmail contacts to limit the length of my list. Now whenever I add someone they get saved to my hotmail contact list, rather than iCloud. How do I change this?

    Settings>Mail,Contacts,Calendars>Default Account (in the Contacts section), set this to iCloud.

  • When recording a video using quicktime and my built in camera (isight) how come the program wont let me use my audio interface rather than the built in mike?

    when recording a video using quicktime and my built in camera (isight) how come the program wont let me use my audio interface rather than the built in mike?

    when recording a video using quicktime and my built in camera (isight) how come the program wont let me use my audio interface rather than the built in mike?
    The basic answer is that Apple has not programmed the capture routine with this capability. As such, you can always send QT feedback requesting this feature be added as a future enhancement.

  • Why not use Jsp for  control in MVC2 ?

    hi
    i am rajendra , i am preparing interview FAQ, so please give me my Que. Ans.
    1) we are using servlet for control in MVC2 Module,then why we can not use
    Jsp for control in mvc2
    2) if we used jsp for control in mvc2 then what is disadvantage compare to if using servlet for control in mvc2
    Please give me ans. as soon as..
    Thanks.

    Are you preparing a FAQ for others or are you just cramming before an upcoming interview and someone gave you a set of questions? It looks more like the latter to me.
    If you haven't actually written any MVC based code, you won't be able to snow the interviewer. It's better to just relax, get a good night's sleep and impress them with your willingness to learn, your fit with the team and whatever real accomplishments you have to show.
    If you really want an answer to this I suggest that you try writing an MVC2 system using JSP for the controller, which is possible, and then try doing the same in a servlet, or better yet using a framework like Spring MVC or Struts to provide the servlet for you and let you concentrate on your application.

Maybe you are looking for