I have a problem with the print of my Vector:
i have this Vector:
Vector<StructRicetta> Ricetta=new Vector<StructRicetta>();
The class StructRicetta:
public class StructRicetta {
String nomeric;
int n;
Vector<String> ingrediente=new Vector<String>();
Vector<String> quantita=new Vector<String>();
Vector<Boolean> facoltativo=new Vector<Boolean>();
String preparazione;
}
I read the value of this structure from a file.
And in the reader function i return to a StructRicetta type and i add it in the vector:
Ricetta.add(Myclass.reader());
Now how can i print the results??
Thank you!
You’re going to have to add a toString() method to your classes, and then iterate through the
Vectors.Perhaps iterate and add each entry to a StringBuilder, and separate using commas or similar ? Apache Commons StringUtils.join() will do this in one call for you.
Note.
Vectoris largely deprecated these days (it’s methods aresynchronisedby default, which is a little wasteful) and you should look at ArrayList or similar instead.