Méthode hashCode() de la classe Java Float avec exemple
Méthode hashCode() de la classe flottante
- méthode hashCode() est disponible dans le package java.lang.
- méthode hashCode() est utilisé pour renvoyer le hashcode de l'objet Float.
- méthode hashCode() est une méthode non statique, elle est accessible uniquement avec l'objet de classe et si nous essayons d'accéder à la méthode avec le nom de la classe, nous obtiendrons une erreur.
- méthode hashCode() ne lève pas d'exception au moment du retour du hashcode.
Syntaxe :
public int hashCode();
Paramètre(s) :
- Il n'accepte aucun paramètre.
Valeur renvoyée :
Le type de retour de cette méthode est int, elle retourne le code de hachage pour cet objet.
Exemple :
// Java program to demonstrate the example // of int hashCode() method of Float class public class HashCodeOfFloatClass { public static void main(String[] args) { // Variables initialization float value1 = 30.20f; float value2 = 10.20f; // It returns hashcode value denoted by this Float f1 object // by calling f1.hashCode() Float f1 = new Float(value1); // Display f1 result System.out.println("f1.hashCode(): " + f1.hashCode()); // It returns hashcode value denoted by this Float f2 object // by calling f2.hashCode() Float f2 = new Float(value2); // Display f2 result System.out.println("f2.hashCode(): " + f2.hashCode()); } }
Sortie
f1.hashCode(): 1106352538 f2.hashCode(): 1092825907