Hello I would like to create a Class which contains an array with the same class.
I tried with the code specified below, but the array i created has been infinite.
public class State {
private String Valor1;
private String Valor2;
private ArrayList arrayStatesAnteriores;
}
And i did the set and get with the refactor of netbeans
state.setArrayStatesAnteriores(arrayStateAnteriores);
But i have the problem of array being infinite. Any idea?
Here’s the way I understand it: You have a class that represents a program’s state in a given moment, and you want to keep a list of the state that the program has had, that’s why you say it’s an infinite list.
First the
Stateclass, which has two fieldsvalue1andvalue2one constructor which sets the two fields to the passed values:Then this class would be contained in an array of
StatesThen you would use this classes in your main or other classes:
Hope it helps feel free to ask more questions.