Put two attributes in a cell

1

Have some structure, List , LinkedList , etc., that allows me to put two attributes in the cell? For example, an integer and a string in each cell.

    
asked by anonymous 12.04.2014 / 18:53

2 answers

2

You would have to do something like this:

class MinhaEstutura {
    public int MeuInteiro;
    public String MinhaString;
}

The structure, in this case, would look like this:

ArrayList<MinhaEstrutura> lista = new ArrayList<MinhaEstrutura>();
    
12.04.2014 / 19:50
0

Example

//Criação e Adição
Map<Integer, String> dic = new HashMap<>();
dic.put(1, "Nome 1");
dic.put(2, "Nome 2");
dic.put(3, "Nome 3");
dic.put(4, "Nome 4");

//Leitura de cada item adicionado
Iterator<Map.Entry<Integer,String>> itr =  dic.entrySet().iterator();
while (itr.hasNext()){
    Entry<Integer,String> item = itr.next();
    System.out.println(item.getKey().toString() + " " + item.getValue());
}
    
13.04.2014 / 02:22