Hi,
This is probably really easy for many of you but i have failed to find the solution. I want to iterate over a vector containing objects of a class i have defined. In every iteration I want to print out some of the member variables of the object. Now, every example i have come across simply casts the entire object in the vector to a String but that is not possible when the objects contains various variables. I was hoping for something as simple as this, but it does nt work:
public Vector getDiscoveryResult(){
Iterator i = servers.listIterator();
while(i.hasNext()){
ServerInfo s = i.next(); //error
System.out.println("IP: " + s.address + ", PORT: " + s.port);
}
return servers;
}
Thanks for any help.
/H
This is probably really easy for many of you but i have failed to find the solution. I want to iterate over a vector containing objects of a class i have defined. In every iteration I want to print out some of the member variables of the object. Now, every example i have come across simply casts the entire object in the vector to a String but that is not possible when the objects contains various variables. I was hoping for something as simple as this, but it does nt work:
public Vector getDiscoveryResult(){
Iterator i = servers.listIterator();
while(i.hasNext()){
ServerInfo s = i.next(); //error
System.out.println("IP: " + s.address + ", PORT: " + s.port);
}
return servers;
}
Thanks for any help.
/H