The Artima Developer Community
Sponsored Link

Java Answers Forum
Looping through a multi-dimensional array

1 reply on 1 page. Most recent reply: Dec 19, 2002 8:57 AM by Justin Gillespie

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Justin Gillespie

Posts: 2
Nickname: dbacks
Registered: Dec, 2002

Looping through a multi-dimensional array Posted: Dec 19, 2002 8:09 AM
Reply to this message Reply
Advertisement
All,

I have a method which returns a multi-dimensional array (always two dimensions, but variable in size). I need to loop through every element to check for the existence of a condition.

Normally in a single dimension array, I would use something like:


for(int i = 0; i < array_name.length; i++)
{
//Do stuff here
}


I notice that the two dimensional array has a length, but I am not sure which length it is returning.

Does anyone have any code snippets for looping through every element in a two dimensional array? I was thinking of using a try-catch block for each dimension to catch each "OutOfArrayIndex" errors, but was thinking that there had to be an easier way.

Thanks in advance for any replies.


Justin Gillespie

Posts: 2
Nickname: dbacks
Registered: Dec, 2002

Re: Looping through a multi-dimensional array Posted: Dec 19, 2002 8:57 AM
Reply to this message Reply
Never mind...I figured it out.


for(int i = 0; i < array_name.length; i++)
{
for(int k = 0; k < array_name[i].length; k++)
{
// Do Stuff Here
}
}

Flat View: This topic has 1 reply on 1 page
Topic: security.policy file Previous Topic   Next Topic Topic: Java and Flat files

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use