i'm trying to build a HashMap having two keys in this way: first i created a class which is only a data structure.
public class Tarta {
public String nome;
public String data;
public Tarta(String nome, String data) {
this.nome = nome;
this.data = data;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}
Then i populated my map by writing this in another class:
mappaTarta.put(new Tarta(nome, data), peso);
During compilation i had no errors, but when testing i got null, for example:
System.out.println(lr.leggiRecord().get(new Tarta("R", "15/11/2015")));
Can you kindly explain me why? Thankyou
hashCodeandequals.TreeMaptoo, you must implementComparable.