Save Integer, Integer, ArrayListInteger in a collection

2

What I want is to do a data binding as follows:

(<<Integer>, <Integer>, ArrayList<Integer>)

I tried to create a HashMap<Integer,HashMap<Integer,ArrayList<Integer>>> the problem is that I forgot that the keys have to be unique and I need to have equal values sometimes.

Ex: (1,1, {1,2,3,4})     (1.2, {1.3})

What is the best way to aggregate this data?

    
asked by anonymous 04.12.2014 / 12:05

1 answer

5

One possible solution is to create the class where you add this data, then create a list of all objects in that class.

//crias a classe com todos os dados que o teu objeto precisa
public class myNewObjecto
{
    private integer num1;
    private integer num2;
    private ArrayList<Integer> listNumeros;

    //crias os get/set

    /
    @Override
    public int hashCode() {
         //implementar o hashCode
    }

    @Override
    public boolean equals(Object obj) {
         //implementar o equals   
    }

}

You create% as_% of your objects:

private ArrayList<myNewObjecto> listmyNewObjecto;

Then you add the data to your object:

//se criares o construtor na class fazes:
myNewObjecto obj = new myNewObjecto(1,2,listaInteiros);
//senão usas os set´s
myNewObjecto obj = new myNewObjecto();
obj.setNum1(1);
obj.setNum2(2);
obj.set(listNumeros);

//adicionas o objeto a tua lista
listNumeros.add(obj);
    
04.12.2014 / 12:57