1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| Map<BiKey<String,String>, Double> map = new HashMap<BiKey<String,String>, Double>();
BiKey<String,String> cle1 = new BiKey<String,String>("hello", "world");
Double valeur1 = new Double(3.14);
map.put(cle1, valeur1);
BiKey<String,String> cle2 =new BiKey<String,String>("array", "object");
Double valeur2 = new Double(1.0);
map.put(cle2, valeur2);
System.out.println(map);
// {(hello, world)=3.14, (array, object)=1.0}
Object test = map.get(cle1);
System.out.println(test.equals(valeur1));
// true
//------------------------------------------------------
// cle3 "identique" au contenu de cle1
BiKey<String,String> cle3 = new BiKey<String,String>("hello", "world");
System.out.println( cle1.equals(cle3) ); // renvoit true
System.out.println( map.get(cle3) ); // renvoit 3.14 |
Partager