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

  • SEARCH
  • Home
  • 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 8814231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:03:50+00:00 2026-06-14T04:03:50+00:00

Maybe this is a stupid question, but i still wonder if i use ArrayList<Integer>

  • 0

Maybe this is a stupid question, but i still wonder

if i use

ArrayList<Integer> Data=new ArrayList<Integer>();
for(int data:Data)
 //some code here
 //print out the iteration times

i want to print out the iteration times (not the execution time)
without using

for int i;i<blahblahblah;i++) output i

for example output

output:
This is iteration times: 1   the data is : blahblahblah
This is iteration times: 2   the data is : blahblahblah
This is iteration times: 3   the data is : blahblahblah
  • 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-06-14T04:03:51+00:00Added an answer on June 14, 2026 at 4:03 am

    Well this may not be correct asthetically

    ArrayList<Integer> Data=new ArrayList<Integer>();
    for(int data:Data)
    {
       System.out.println( Data.indexOf(data)+1 );
       Data.remove(Data.indexOf(data));//to ensure the index is correct even if there are duplicates
    }
    

    since for each loop accesses the elements sequentially it will give you the iteration number = (index + 1)

    Edit:
    If you can remove the element you can ensure that the duplicates problem will not occur. Or else the traditional for loop is best suited

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

Sidebar

Related Questions

Maybe this is a very stupid question but... Why should I use tinytext and
This is maybe a stupid question, but since I am relatively new to UDP
This is maybe a stupid question, but I want to know if my code
Maybe this is a stupid question, but I am wondering if I use dropbox
I'm still quite new to ASP.Net MVC, so maybe this is a stupid question.
Maybe this is a stupid question, but I dont know how to use Membership
I'am new to jquery and maybe this is a stupid question but I have
This may be a stupid question to ask, but still I need to know
maybe this is a stupid question but : i run perl 5.8.8 and i
Well, maybe it is a stupid question, but I cannot resolve this problem. In

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.