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 6364881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:13:17+00:00 2026-05-25T00:13:17+00:00

I had posted a question earlier attempting to find an error in my code,

  • 0

I had posted a question earlier attempting to find an error in my code, and the main problem was that I had used a for each loop incorrectly. I’m new to Java and was wondering why what I had attempted was incorrect and if there would be any possible way of doing the task with a for each loop.

public Dids(String thing)
{
    letters= new char[thing.length()];  
    for(char i: letters){
        letters[i] = thing.charAt(i);
    }
}

My thought was that since I had declared the size of the array before the loops, that I would be able to iterate through it.

  • 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-25T00:13:18+00:00Added an answer on May 25, 2026 at 12:13 am

    With foreach constructs, there is no counter for the current index, just the value at the index. The variable ‘i’ is the value at the current point in the array.

    You can do this with an ordinary for loop

    for (int i=0; i<letters.length; i++)
       letters[i] = thing.charAt(i);
    

    Or more concisely,

    char[] letters = thing.toCharArray();
    

    See String.toCharArray()

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

Sidebar

Related Questions

I had posted another question earlier about deployment with Passenger. That problem turned out
I had posted a question in regards to this code. I found that JTextArea
Hi I posted a question a little earlier and I had some replies that
I have had a long problem with this code. I have posted this question
I had posted one question earlier jQuery inconsistency in setting readonly attribute in IE-8
I had posted a similar question earlier - a slightly different requirement here. I
This question is related to another question that I posted on SO earlier How
I had earlier posted a question, regarding same, but over here i want guidance
(This is technically an addendum to an earlier StackOverflow question I had posted, but
Guys i had posted a question earlier pypdf python tool .dont mark this as

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.