org.javatuples方法中的hashCode()方法返回JavaTuple类对象的哈希码。如果对象不变,则哈希码始终相同。 Hashcode是由JVM在对象创建时生成的唯一代码。它可用于对与哈希相关的算法(例如哈希表,哈希图等)执行某些操作。也可以使用此唯一代码搜索对象。
方法声明:
public final int hashCode()
用法:
int code = TupleClassObject.hashCode()
这里TupleClassObject表示JavaTuple类,如Unit,Quartet,Decade,KeyValue等使用。
返回值:它返回一个整数值,该整数值表示此TupleClassObject的hashCode值。
以下示例程序旨在说明TupleClassObject的hashcode()方法:
程序1:获取四方类对象的哈希码。
// Below is a Java program to use hashCode() 
// with a LabelValue tuple 
  
import java.util.*; 
import org.javatuples.Quartet; 
  
class GfG { 
    public static void main(String[] args) 
    { 
        // Creating a Quartet with 4 values 
        Quartet<Integer, String, String, Double> quartet 
            = Quartet.with(Integer.valueOf(1), 
                           "GeeksforGeeks", 
                           "A computer portal", 
                           Double.valueOf(20.18)); 
  
        // Using the hashCode() method 
        int code = quartet.hashCode(); 
  
        // Printing the returned hashCode 
        System.out.println(code); 
    } 
}输出:
-1296686340
程序2:获取LabelValue类对象的哈希码。
// Below is a Java program to use hashCode() 
// with a LabelValue tuple 
  
import java.util.*; 
import org.javatuples.LabelValue; 
  
class GfG { 
    public static void main(String[] args) 
    { 
        // Creating a LabelValue object 
        LabelValue<Integer, String> lv 
            = LabelValue.with(Integer.valueOf(1), 
                              "A computer science portal"); 
  
        // Using the hashCode() method 
        int code = lv.hashCode(); 
  
        // Printing the returned hashCode 
        System.out.println(code); 
    } 
}输出:
-1587127699
注意:同样,它可以与任何其他JavaTuple类一起使用。
相关用法
- Java JavaTuples contains()用法及代码示例
- Java JavaTuples add()用法及代码示例
- Java JavaTuples with()用法及代码示例
- Java JavaTuples indexOf()用法及代码示例
- Java JavaTuples getLabel()用法及代码示例
- Java JavaTuples getKey()用法及代码示例
- Java JavaTuples setKey()用法及代码示例
- Java JavaTuples toString()用法及代码示例
- Java JavaTuples equal()用法及代码示例
- Java JavaTuples fromIterable()用法及代码示例
- Java JavaTuples containsAll()用法及代码示例
- Java JavaTuples getSize()用法及代码示例
- Java JavaTuples getValue()用法及代码示例
- Java JavaTuples fromArray()用法及代码示例
- Java JavaTuples setLabel()用法及代码示例
注:本文由纯净天空筛选整理自RishabhPrabhu大神的英文原创作品 JavaTuples hashcode() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
