• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

JAVA Array: Add


Dear experts:

Hi!

I  would like to know whether I may objects to a panel using "for loop" as seen below.

Thanks a lot!


____________________   Want-to-try Code ________________

for ( int index = 0;  index < array.length; index++  )
  {
     topPanel.add (button [index]);
     
  }
     
     
   _________________   Current Code  _________________  
     
     topPanel.add  (  button [ 0 ] );
     topPanel.add  (  button  [ 1 ] );
     topPanel.add  (  button  [ 2 ] );
     topPanel.add  (  button  [ 3 ] );
   
  _________________________________________________
     
0
duta
Asked:
duta
  • 2
1 Solution
 
objectsCommented:
yes thoses two are equivalent (assuming size of array is 4)
0
 
dutaAuthor Commented:
Savant, thank you so much for your kind, prompt reply.

Yes, they are the same. I wonder whether I may replace the lengthy second one with the first one.

I tried but I got some error message.

Thanks!
0
 
objectsCommented:
> for ( int index = 0;  index < array.length; index++  )

should be:

for ( int index = 0;  index < button.length; index++  )

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now