The moose likes Beginning Java and the fly likes for loop help Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 436

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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: for loop help
 
Similar Threads
Sorting Issue Help Needed Badly
What does the dimension of an array refer to?
How to use logic:iterate tag
Constructing multidimensional arrays
TextField and setEditable