當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java CompoundName hashCode()用法及代碼示例


javax.naming.CompoundName類的hashCode()方法用於返回此化合物名稱的哈希碼。該複合名稱對象的哈希碼是該複合名稱各個組成部分的“canonicalized”形式的哈希碼的總和。

用法:

public int hashCode()

參數:此方法不接受任何內容。



返回值:此方法返回一個表示此名稱的哈希碼的int。

以下示例程序旨在說明CompoundName.hashCode()方法:
程序1:

// Java program to demonstrate 
// CompoundName.hashCode() 
  
import java.util.Properties; 
import javax.naming.CompoundName; 
import javax.naming.InvalidNameException; 
  
public class GFG { 
    public static void main(String[] args) 
        throws InvalidNameException 
    { 
  
        // need properties for CompoundName 
        Properties props = new Properties(); 
        props.put("jndi.syntax.separator", ":"); 
        props.put("jndi.syntax.direction", 
                  "left_to_right"); 
  
        // create compound name object 
        CompoundName CompoundName1 
            = new CompoundName( 
                "a:b:z:y:x", props); 
  
        // apply hashCode() 
        int hashCode 
            = CompoundName1.hashCode(); 
  
        // print value 
        System.out.println("hashCode:"
                           + hashCode); 
    } 
}
輸出:
hashCode:558

程序2:

// Java program to demonstrate 
// CompoundName.hashCode() method 
  
import java.util.Properties; 
import javax.naming.CompoundName; 
import javax.naming.InvalidNameException; 
  
public class GFG { 
    public static void main(String[] args) 
        throws InvalidNameException 
    { 
  
        // need properties for CompoundName 
        Properties props = new Properties(); 
        props.put("jndi.syntax.separator", "/"); 
        props.put("jndi.syntax.direction", 
                  "left_to_right"); 
  
        // create compound name object 
        CompoundName CompoundName1 
            = new CompoundName( 
                "c/e/d/v/a/b/z/y/x/f", 
                props); 
  
        // apply hashCode() 
        int hashCode 
            = CompoundName1.hashCode(); 
  
        // print value 
        System.out.println("hashCode:"
                           + hashCode); 
    } 
}
輸出:
hashCode:1078

參考文獻:https://docs.oracle.com/javase/10/docs/api/javax/naming/CompoundName.html#hashCode()




相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 CompoundName hashCode() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。