Reputation: 27
have this class
public class Taxonomia {
private static ArrayList<String> hijas;
private static String padre;
public Taxonomia (String p, ArrayList<String> h){
hijas = h;
padre = p;
}
}
used in another class like this:
public class TablaSimbolica {
private static ArrayList<Taxonomia> taxonomias = new ArrayList<Taxonomia>();
public static void addTaxonomica(){
System.out.println("enter value: ");
String padre = Entrada.read(); //reads input and returns String
System.out.println("entre value comma separated: ");
String reemplazado = Entrada.read();
ArrayList<String> items = new ArrayList<String>(Arrays.asList(reemplazado.split("\\s*,\\s*")));
Taxonomia t = new Taxonomia (padre, items);
taxonomias.add(t);
}
when called from the main simple as this (print its just a for...)
TablaSimbolica.addTaxonomica();
TablaSimbolica.addTaxonomica();
TablaSimbolica.printTax();
all the objects are the same, and i cant figure out where it is im missing the creation of a new object or something like that. thanks in advance!
Upvotes: 0
Views: 3680
Reputation: 178253
Your class variables in the Taxonomia
class are static
, meaning only one of each for the entire class, no matter how many instances.
Make it one per instance by removing static
. Change
private static ArrayList<String> hijas;
private static String padre;
to
private ArrayList<String> hijas;
private String padre;
Upvotes: 1