Vérifier si une valeur existe dans Hashtable en Java

La méthode contains() de Hashtable retourne true si la valeur recherchée se trouve dans la collection Hashtable, sinon elle retourne une valeur false.

import java.util.Hashtable;

public class Main {
public static void main(String[] args) {
Hashtable<String, String> ht = new Hashtable<String, String>();

ht.put("1", "un");
ht.put("2", "deux");
ht.put("3", "trois");

boolean b = ht.contains("trois");
System.out.println("La valeur trois existe dans Hashtable ? : " + b);
}
}
Exécution:

La valeur trois existe dans Hashtable ? :true
Advertisement

AdBlock Detected

Please disable your ad blocker and refresh the window to use this website.