Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7610617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:27:38+00:00 2026-05-31T01:27:38+00:00

I have a collection like follows: final List list = new ArrayList(3); Is it

  • 0

I have a collection like follows:

  final List list = new ArrayList(3);

Is it effecient to do something like below

    for (final Iterator iter = list.iterator(); iter.hasNext();)
    {
        // do something
    }

OR

for(final Object obj : list){
// do something 
}

?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:27:40+00:00Added an answer on May 31, 2026 at 1:27 am

    The second example is just a shortcut syntax for the first one. They’re essentially the same thing (assuming you call final Object obj = iter.next(); in your for loop).

    The shortcut syntax, known as “for-each” or “enhanced for”, is more typically used since it’s cleaner, more intuitive, and as Péter Török notes avoids potential bugs. I only recommend the plain syntax when it’s needed for its greater flexibility.

    See this article for more information: http://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string
Another easy one hopefully. Let's say I have a collection like this: List<DateTime> allDates;
I have mongo collection like below { auther : xyz , location : zzz
I have a collection I'd like to query as follows: return all documents up
I have an object like follows: @connection.register class User(Document): __collection__ = 'users' __database__ =
I have an Array Collection as follows var myArr:ArrayCollection = new ArrayCollection([ {label: label1,
Suppose I create collection like Collection<IMyType> coll; Then I have many implelentations of IMyTypem
I have a collection of MODS records that looks like this: <modsCollection> <mods [namespaces
I have a collection of objects to which I'd like to just add a
I have a collection of orders. I would like to hit the database once,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.