• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

for loop help

 
dale conn
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now solved
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic