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.
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.
2
You’d 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>();
Just one detail, but to follow the Java pattern, I suggest starting the variable name with lowercase: meuInteiro
, minhaString
.
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());
}
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.
Could you explain what the use would be? I found your question a little vague, I’m not sure what your question is.
– Math