Is Iterator class really necessary for our lifes?

I'm reading about Iterator class and how to use it, but a doubt arrise. Is it really necessary?
Take a look at my code bellow:
import java.util.*;
public class Main {
    public static void main(String[] args) {
        ArrayList ar = new ArrayList();
        for (int i=0;i<20;i++)
            ar.add(i);
        //Method 1
         for(int i=0;i<ar.size();i++)
            if (((Integer)ar.get(i) % 2) != 0)
                ar.remove(i);
        //Method 2
        Iterator it = ar.iterator();
        while(it.hasNext())
            if (((Integer)it.next() % 2) != 0)
                it.remove();
        System.out.println("The even numbers are: ");
        for(int i=0;i<ar.size();i++)
            System.out.println((Integer)ar.get(i));
}In the code above, we have two ways to do the same thing, both works fine, but using the Method 2 I needed to code one line more instancing a new class Iterator.
Can anyone tell me in which circuntances I really need to use a Iterator and why?
Thanks

Additionally, Iterator works on all Collections. For Sets, there is no get(i). If you have a method that returns a Collection, and that Collection might be a LinkedList or an ArrayList or a HashSet or something else, the Iterator is the gauranteed way to walk through it, regardless of what class it is. And with enhanced for loop, it's quite clean and simple.
Collection<Thing> things = thingFetcher.fetchACollectionOfThings(); // LinkedList? HashSet? We don't know and don't care
for (Thing thing : things) {
  thing.doStuff();
}

Similar Messages

  • Is an admin server (WebLogicAdmin) really necessary for production PIA?

    Greetings:
    We're on PT 8.50 and WebLogic 10.3 on Windows 2008 R2. The PT install instructions say the Multi Server Domain config option is intended for production environments but I'm not sure that's necessary in all cases. For instance, if PSOL and PSEMHUB are hosted on another server configured Multi Server Domain why would you need to configure another Multi Server Domain just for PIA? Is there any benefit to that? It seems to me there would be less overhead running a Single Server Domain for PIA but I am not an expert. Any input, pros/cons, experience is appreciated. We are a small to medium sized FSCM 9.0 installation - no WebLogic clusters or anything.
    Thanks!
    John

    It's not really necessary to have a multi weblogic domain setup if you're not going to assign multiple IP addresses to the server running Weblogic. The multi domain setup will only use its full potential when you go for a failover and load balancing setup. This way you assign a different IP to each of the PIA instances. A load balancer will then balance the load between the PIA instances. The reason why Oracle recommends having a multi server domain is for when you have the PeopleBooks running on the same server. This is because the PeopleBooks might affect your PeopleSoft production environment when it's having problems. With a single server domain only one webserver will be handling the load for both the PeopleBooks and PeopleSoft. If there's a servlet failing on the PeopleBooks for some reason then it will cause problems.
    If the PeopleBooks are running on a seperate server you're theoretically already running a multi server setup. I don't see a reason why you can't use the single server domain.

  • Is it really necessary for me to replace my STB 7100 series with this new multi-room DVR?

    I just wanted to know other people's opinions on this because so far, I'm leaving my existing setup alone.  I was looking on line to see what upgrades may be available to me and the multi-room DVR is one of them, which now I see is not only available to just new customers. 
    But here are some of the reasons for my hesitance about switching:
    - I never record anything and I never will.  People say "never say never" but that's one "never" statement that I make pretty confidently.
    - I only have one TV in my house, just in the living room. 
    So I guess my question is, "What would I gain, if anything?"  Or would getting that new DVR be good preparation for further upgrades in the TV Guide Display? 
    As long as I can watch my TV and all the basics are working as they should, that's really all that matters to me. 
    Solved!
    Go to Solution.

    Based on your comments you don't need a DVR.
    However if you were to decide to get one you only should get a HD DVR.  The multi-room is a software feature, not different hardware, that can be enable if you ever setup an additional stb for another room.  The multi-room feature is an additional $4 over the price of the DVR.

  • Is NetWeaver really necessary for GTS?

    Hi,
    Just wanted to know if for GTS we should and must have netweaver or is there any version of GTS which runs without netweaver for 4.6c?
    Thanks,
    Shruthi

    Hi Shruthi,
    SAP GTS is based on SAP Net Weaver technology.It can be connected to both SAP and non-SAP feeder systems through Net weaver.
    To communicate with other systems,You need interfaces and need to set up communication between them, for example, to connect external converter systems, which convert your IDocs into the official data formats for electronic communication with the customs authorities. For this and many other similar functions you require Net weaver.
    For more info you can check: SAP Library for SAP Net Weaver under help.sap.com ® Documentation ®SAP Net Weaver ®SAP-Net Weaver Library ®SAP Net Weaver by Key Capability ®Application Platform by Key Capability ® Connectivity ® Components of SAP Communication Technology
    Regards
    Vivek

  • Is Business Catalyst upgrade really necessary for a non-google email account?

    I just started hosting my site on Business Catalyst hosting through my Creative Cloud subscription. I updated the domain to be my own register domain name.
    I was led to believe that I could permanetly use Business Catalyst as my hosting. Am I wrong?? Is it only for temporary work to post for 30days and display to clients??!!!
    When I went to add email accounts I learned that I needed to purchase one of their hosting plans. Is this true!!??

    Hi,
    When you publish a site to BC, it is first published in a trial mode. However, you can Launch the site from the BC site's admin panel to make it live. Your BC site will be active as long as your Cloud subscription is active.
    Regarding emails, the free site you get with Cloud subscriptions, are on basic plan and doesn't include the email feature. However, you can still add external MX record and use external email service such as google mail. If you want to use the BC email service, than you need to upgrade the site plan.
    Hope this helps.
    Regards,
    Aish

  • CU51 really necessary?

    Hi all,
    We enter KMAT and configuration values in SD order.
    In order to have our BOM exploded according to configuration in Production order, we need to go CU51 and save the configuration.
    The question is, CU51 is really necessary for activating configuration ? Because we never change anything in the BOM over CU51, which is to explode according to Sales order item characterictic values. I wish, the BOM explodes in production order appropriately without visiting CU51
    Thanks

    In order to ensure that an order BOM is exploded, one of the following steps must be performed:
    Before saving a sales order in the transaction VA01 or VA02, make sure to go to "Engineering" from within the configuration.
    Save the Order/Item in the transaction CU51.
    Activate the switch GV_FORCE_BOM_EXPLOSION_ASL (Include LCUKOFBE) from SAP note 303446. This switch forces an explosion of the order BOM from within the sales order, without going to the "Engineering" view.
    Use the report RCU_CU51_DARK from SAP notes 371188 and 384624.

  • Is a PDF reader really necessary on iPad?

    Is a PDF reader really necessary for iPad? I haven't needed one yet ... I don't think.

    Depends on what you want to do with the PDF's and how you're getting them on the iPad. Originally, when the iPad came out in spring of 2010, there was no native PDF reader (except for emailed PDF's). Goodreader was one of the first apps to cater to PDF reading, and others came up, so there are a number of PDF apps. As time went on iBooks was given PDF ability, and for most people that's fine, but apps such as Goodreader have additional features.
    If you haven't needed one yet, don't worry about it - just use iBooks or the mail reader. If you find yourself in need of a more sophisticated app, then just visit the App Store and see what meets your needs.

  • I have just updated my plug in & add ons, but they are several that say to research. How do I know what plug ins are necessary for mozilla to run properly. I really don't want a bunch of unnecessary downloads on my computer

    I have just updated my plug in & add ons, but they are several that say to research. How do I know what plug ins are necessary for firefox to run properly. I really don't want a bunch of unnecessary downloads on my computer

    None are '''''necessary''''' to use Firefox, but some parts of some web pages aren't going to work without a specific plugin being installed.

  • SLIN issues error for jvascript code in iterator class.

    Hi All,
    concatenate '<input o n Change=checkValidity(this.value,"' p_cell_id '");' into replace .
    If i check the iterator classes in SLIN Extended syntax check it throws error
       Program:  ZCL_SRM_OCI_ITERATOR==========CP  Include:  ZCL_SRM_OCI_ITERATOR==========CM002  Row:     99  [Prio 3]
    Char. strings w/o text elements will not be translated:
    '<center>End Date</center>'
    The message can be hidden with "#EC NOTEXT)
    But even after giving "#EC NOTEXT after the specified line in iterator class code I get the same error in SLIN.
    Kindly suggest how to hide this error.
    Regards,
    Anubhav

    This frankly is terrible, terrrible, terrible advice.If it wasn't obvious, and probably it wasn't obvious to the adviser: granting all permissions grants all permissions to all applets. So once you do that, any applet you download from any site has permission to do anything it likes on your system.
    It might be worthwhile for some spammer or malware writer to write an applet that looks for stupid people who have done this to their systems.
    And here's another reason why it's terrible advice: it only solves the problem for one computer. If somebody else wants to run your applet off your website then you have to give them the same advice, and now you move from stupidity to criminal negligence.
    And if you only ever plan to run it on your own computer, there was no point in writing an applet in the first place. Java applications don't have to deal with the security issues.

  • I'm making a DVD for our class reunion.  A fellow classmate has some video on a mini cassette that he said he could put on a dvd.  Will I be able to import from that dvd to imovie to use in my dvd?

    I'm making a DVD for our class reunion.  A fellow classmate has some video on a mini cassette that he said he could put on a dvd.  Will I be able to import from that dvd to imovie to use in my dvd?  Or does it have to be in another format, maybe flash drive? 

    Ask your friend to supply you the DVD as a data DVD using either DV or AIC as the video format, burning the DVD as a DVD for a DVD player will degrade the video quality.

  • No-arg constructor for SQJL iterator class

    I'm to use SQLJ with EJB:
    I used SQLJ to define a public DeptRecs:
    #sql public iterator DeptRecs implements java.io.Serializable
    ( int deptNo, String dName, String loc );
    I wish to pass the iterator out of EJB:
    DeptRecs departments = deptEJB.getDepartments();
    As EJB communication is based on object serialization /
    deserialization, it is critical to provide a no-arg constructor
    for all the classes passed. But the SQLJ iterator has only one
    constructor:
    public DeptRecs(sqlj.runtime.profile.RTResultSet resultSet)
    How can I have a no-arg constructor for the iterator class?
    Or if this is a wrong way to have SQLJ work with EJB, could
    anybody tip me the correct structure?

    You may want to look at the following SQLJ demo file:
    sqlj/demo/SubclassIterDemo.sqlj
    This demonstrates the following:
    - a class Emp to hold the values of the rows
    - a subclass EmpColl of the iterator to read the rows into Emp
    objects.
    The EmpColl class has a getEmpVector() method that returns a Java
    vector with Emp objects as elements. Such a vector would be
    serializable and can be passed around. However, you are likely
    not able to pass the original iterator or its EmpColl subclass
    around.

  • How can I download printable invoices for our monthly Creative Cloud payments?

    This is killing me. How can I have spent almost an hour and yet for the life of me, cannot find anywhere on the Adobe site that will let me view, print, download invoices for our monthly subscription payments? I go to My Orders, but all that is there is our initial Creative Cloud subscription payment. Can't find previous months payments anywhere.
    Why is this so difficult?
    Every month or so our accounts department is on my back asking for the invoices so they can match it up with the company credit card records. And every time, this is an issue.
    Most companies we work with send an invoice paid email with the invoice attached as a PDF. Isn't that better than the standard Confirmation: We received your Adobe Creative Cloud payment email that gets sent out? What good is it if we can't find any reference for such payment?
    Sorry guys, I'm just really furious that I am wasting so much time on such a menial task while I have deadlines looming.
    Also, it's been over 30 minutes and I'm still waiting for the 9 minutes web chat said it would take for an operator to get back to me.

    Hi Mversion76,
    This thread might be helpful
    http://forums.adobe.com/message/4498407#4498407#4498407#4498407
    -Dave

  • Is 2 GB Ram really necessary?

    Looking to upgrade my gf's Macbook.
    1 GB = $99
    2 GB = $225
    Given OSX's good memory management quality, and the fact that she will mainly do web design and LogicPro 7 work on the Macbook, is the 2 GB really necessary or will it be more like overkill?
    We had 2 GB in our old powerbooks and it seemed to make little real-world everyday difference between 1 GB of Ram.
    Thanks for any comments...

    I'm running 2G of Ram with Logic Pro 7. It's well worth the money if you can afford it. And it also depends on what you're going to within Logic Pro 7. But so far, I've noticed a HUGE difference...things are running a lot smoother than before the memory upgrade.
    Having said that, 1G should be sufficient. Of course, Logic Pro 7 is running Universal. So you're going to get your money worth. And plus, your gf is going to love you for the 2G upgrade.
    Web-design takes less "stress" than using Logic. But then again, if she's a professional web-designer and going to use Photoshop with it...keep in mind that it's not Universal yet. But when the update is ready, I'm sure it will fly with 2G of Ram.
    Not all 3rd party plug-ins for Logic Pro 7 are universal yet...so performance is going to suffer a little when running those plug-ins.
    Live 5.2 is UB and Reason 3.0.5 is also UB. If you really want to surprise your gf, get these 2 music production softwares, she will love using them with Logic Pro 7. I know, I'm a little off topic, just some suggestions. Any day is Valentine day.
    Patrick

  • Is the rating system really necessary?

    I know... I know... I'm probably getting on a touchy subject here.
    I understand the desire for a sort of incentive for people to answer questions but it is my observation that use of points is hardly consistent. For the most part, it seems like questions from established users tend to get helpful and solved answers most of the time. Great. The point system works in that instance.
    I have also noticed that I will see someone come on the boards, post a question, get their answer and never post again. They either don't know about the rating system or they do not stay long enough to use it.
    Does that mean I need to look at the O.P.'s post count before I post an answer? I think that's shallow. If someone has question and I think I know a solution, then I will post a solution.
    But what is the solution? Do away with the rating system? I think some upper-level members would have a justifiable objection to that. Change it to a raw post count? I suspect we would see an even higher number of posts deleted because of people trying to pad their numbers.
    What if members received 1 point for marking an answer as helpful and 2 points for marking an answer as solved?
    Its a thought.

    No, the rating (reputation) system isn't really necessary, but it does serve as an incentive for many people to increase their participation, and increased participation lends itself to the perception of increased value in this Apple-provided service, if not to the usefulness of the bulk of the posts that are left here.
    Ultimately, there are a lot of things that go into the decision to attach a reputation system of one kind or another to Discussions, and there has been one such system or another in place here for many years, so there is no reason to believe that the concept will ever be abandoned.
    As to the idea that upper-level members would object to its loss, yes, some would. Maybe many. On the other hand, there are quite a few of us who see through this charade and do what we can do undermine its importance relative to the real mission of Apple's Discussions. In the end, I'd like to think that our cynicism helps to balance out the "shallowness" of post-count building and points-grubbing strategies that seem to obsess many of our peers.
    What if members received 1 point for marking an answer as helpful and 2 points for marking an answer as solved?
    I've suggested this myself in the past, but one of the roadblocks to its implementation is that the current software is only able to mete out points in increments of 5. Oh well....
    Good luck!

  • Is 'Leopard' really necessary?

    Hi again..
    I've been reading different threads on this topic (some of which were negative on various Leopard features) and was just wondering whether it was really necessary to install Leopard?
    We only recently bought our Mac and I was just concerned that I might end up with unnecessary problems....
    What are the benefits of (or purpose in) installing this software/upgrade?
    Any information on this would be appreciated, thanks!

    After one week using Leopard, I was ready to say it was far more trouble than it was worth. Against my better judgement, I decided to do the default "Upgrade" install, but not before I made a clone of my Tiger startup disk, & it would have been a nightmare without that. The install seemed to go fine but my iMac would not restart completely -- no menu bar, no Finder, & a stuck Dock. I tried a lot of things but ultimately had to erase the drive from Disk Utility on the Leopard DVD -- Erase & Install would not even work from within the installer, repeatedly giving me a message about not being able to unmount the target volume. But after around 12 hours total effort, I successfully installed it 'from scratch' on the newly reformatted drive & used Setup Assistant to migrate everything from the clone.
    I have no idea why I had these problems: I had used Tiger's latest version of Disk Utility prior to the first attempt to verify that the Tiger install had correct permissions & that the file system was OK. I had no third party hacks installed (& I'm obsessed enough about the evils of such things to know how to find them, even when stuck into the nooks & crannies of the OS). "Clean" is an overused term, but my Tiger OS was as pristine as I know how to make it, drawing on almost two years of active participation in these forums & everything all its gurus taught me.
    Anyway, even after getting it installed successfully, & doing everything suggested here & elsewhere to make sure it was in good health, I had a variety of small & not-quite-so small problems. The 10.5.1 update helped some, as did Apple's k-base articles about repairing oddities introduced by upgrading from Tiger & such, but it still was disappointingly unstable compared to 10.4.10. Worse, I learned that several of my mainstay apps weren't Leopard-compatible.
    But I stayed with it, partially because I could always reboot into Tiger with my clone when I needed to, partially because I'm just stubborn enough not to want to admit defeat, but mostly because the new feature set really does have a lot to offer that Tiger does not. The biggies like Time Machine are great but I find all the little refinements are really what I like most. For example, I didn't think something as simple as being able to display the path in the bottom of all Finder windows (like in Spotlight searches) would be such a boon, but it is. Spotlight is still far from perfect but Boolean searches make it much more powerful.
    Long story short(er), I find that when I need to boot back into Tiger, I really miss all the little things it won't do that Leopard will. There are still some rough edges & things that need to be rethought, & it still isn't as stable as I would like but overall, as the two months of use mark approaches, I do not regret buying it & making it my mainstay OS version.
    Necessary? No. Worth it? It is for me.

Maybe you are looking for