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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:32:00+00:00 2026-05-28T18:32:00+00:00

i watch in a tutorial that i can traverse an array of object in

  • 0

i watch in a tutorial that i can traverse an array of object in this way:

     Animals[] an = new Animals[2];

         for (Animals a:an){
                 .
                 .
         }

But now i want to traverse a 2 dimensional array and when i use this code i have a problem(says:incompatible types
required:appl1.Animals
foundLappl1.Animals[]). when i use this code

   Animals[][] an = new Animals[2][2];

      for (Animals a:an){
             .
             .
       }

Does anyone knows how can i overcome this problems. Thank you in advance for your help.

  • 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-28T18:32:01+00:00Added an answer on May 28, 2026 at 6:32 pm

    You will need to use nested loops, as follows:

    Animals[][] an = new Animals[2][2];
    
    for (Animals[] inner : an) {
        for (Animals a : inner) {
            // Execute code on "Animals" object a
        }
    }
    

    Why does this work?

    Look at your first example (reposted here for convenience):

    Animals[] an = new Animals[2];
    
    for (Animals a : an) {
        // Do stuff here.
    }
    

    This works because an is an array of Animals objects. The for loop iterates through each Animals object, performing some action on them one-by-one.

    Now look at my answer posted above (again, reposted here for context):

    Animals[][] an = new Animals[2][2];
    
    for (Animals[] inner : an) {
        for (Animals a : inner) {
            // Execute code on "Animals" object a
        }
    }
    

    This works because an is an array of Animals[] objects. The first for loop iterates through each Animals[]. At that point, you have an array of Animals objects, so you can use the same solution as above: a single for loop to iterate through each of the Animals object and perform some action on them one-by-one.

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

Sidebar

Related Questions

Ok, sorry if this question is stupid. I followed this tutorial: http://www.youtube.com/watch?v=E30_-pQGQXs . Now
I was following this tutorial on http://www.youtube.com/watch?v=LBnPfAtswgw and was able to replicate that in
I was about to start learning x64 assembly using this tutorial (series) but setting
I'm new in Cocoa-Touch. Please look at this links: http://www.youtube.com/watch?v=Cab8CB_Lzbw http://www.youtube.com/watch?v=8c8KA1uZ9F8&feature=autoplay&list=PL6EFB1A1E5CAA7666&lf=results_main&playnext=1 I really want
I've been following this tutorial - http://www.youtube.com/watch?v=R2hOvZ7bwXU , which explains how to use postMessage
I downloaded squeak 4.2 http://squeak.org/ and watch this very basic tutorial http://www.youtube.com/watch?v=0w1Yub4eUAU When I
I want to watch a folder tree on a network server for changes. The
I want to watch all the HTTP requests going out of a certain application
How can I watch the messages being sent back and for on urllib shttp
Is there a way to watch for changes in the ip-address much the same

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.