wood burning stoves*
The moose likes Beginning Java and the fly likes for loop help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "for loop help" Watch "for loop help" New topic
Author

for loop help

dale conn
Ranch Hand

Joined: Jun 16, 2006
Posts: 57
hi there i'm trying to iterate through a for loop but getting a bit stuck

MyArray[] myarray = getArray(a, b, c, d)

Returns an array. when i look at the array in my java debug, i can see the id and and name. how do i iterate
throught the loop setting the id and name values to variable?

When i look at myarray in a debugger i have this

myarray = MyArray[3]
expand the first one
id = "123"
name="some name"
etc

for (int i=0; i < myarray .length; i++) {
System.out.println("length: " + myarray [i]); // i know there's data
String id = /// how do i get the id ?
String name // how do i get the name?
}

thanks for any help
dale conn
Ranch Hand

Joined: Jun 16, 2006
Posts: 57
now solved
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Hi Dale,

What exactly do you mean by the id and the name here? Do you mean the index of each element?


Does this help you?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by dale conn:
hi there i'm trying to iterate through a for loop but getting a bit stuck

for (int i=0; i < myarray .length; i++) {
System.out.println("length: " + myarray [i]); // i know there's data
String id = /// how do i get the id ?
String name // how do i get the name?
}

thanks for any help


i think you are struggling to convert string from MyArray
if yes... first you convert into Object then use toString()for converting into String
Santhi Bharath
Ranch Hand

Joined: Jun 03, 2008
Posts: 75
hi dale conn,

can you explain

what is arrayid and explain how you have resolved the problem,what is the problem with earlier code?


that will help us.


thanks and regards<br />Santhi Bharath<br />SCJP 5.0, SCWCD 5.0
 
 
subject: for loop help