
- Java.util 包類
- Java.util - 首頁
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util 包擴充套件
- Java.util - 介面
- Java.util - 異常
- Java.util - 列舉
- Java.util 有用資源
- Java.util - 有用資源
- Java.util - 討論
Java Vector hashCode() 方法
描述
Java Vector hashCode() 方法用於返回此向量的雜湊碼值。
宣告
以下是 java.util.Vector.hashCode() 方法的宣告
public int hashCode()
引數
無
返回值
方法呼叫返回此列表的雜湊碼值(int)。
異常
無
獲取整數向量雜湊碼示例
以下示例演示瞭如何使用 Java Vector hashCode() 方法獲取此向量的雜湊碼。我們使用 add() 方法呼叫每個元素將幾個整數新增到 Vector 物件中,並使用 hashCode() 方法獲取雜湊碼並列印它。
package com.tutorialspoint; import java.util.Vector; public class VectorDemo { public static void main(String[] args) { // create an empty Vector vec with an initial capacity of 4 Vector<Integer> vec = new Vector<>(4); // use add() method to add elements in the vector vec.add(4); vec.add(3); vec.add(2); vec.add(1); // let us get the hashcode of the vector System.out.println("Hash code: "+vec.hashCode()); } }
輸出
讓我們編譯並執行上述程式,這將產生以下結果:
Hash code: 1045631
獲取字串向量雜湊碼示例
以下示例演示瞭如何使用 Java Vector hashCode() 方法獲取此向量的雜湊碼。我們使用 add() 方法呼叫每個元素將幾個字串新增到 Vector 物件中,並使用 hashCode() 方法獲取雜湊碼並列印它。
package com.tutorialspoint; import java.util.Vector; public class VectorDemo { public static void main(String[] args) { // create an empty Vector vec with an initial capacity of 4 Vector<String> vec = new Vector<>(4); // use add() method to add elements in the vector vec.add("Welcome"); vec.add("To"); vec.add("Tutorialspoint"); // let us get the hashcode of the vector System.out.println("Hash code: "+vec.hashCode()); } }
輸出
讓我們編譯並執行上述程式,這將產生以下結果:
Hash code: -1700837919
獲取物件向量雜湊碼示例
以下示例演示瞭如何使用 Java Vector hashCode() 方法獲取此向量的雜湊碼。我們使用 add() 方法呼叫每個元素將幾個 Student 物件新增到 Vector 物件中,並使用 hashCode() 方法獲取雜湊碼並列印它。
package com.tutorialspoint; import java.util.Vector; public class VectorDemo { public static void main(String[] args) { // create an empty Vector vec with an initial capacity of 4 Vector<Student> vec = new Vector<>(4); // use add() method to add elements in the vector vec.add(new Student(1, "Julie")); vec.add(new Student(2, "Robert")); vec.add(new Student(3, "Adam")); // let us get the hashcode of the vector System.out.println("Hash code: "+vec.hashCode()); } } class Student { int rollNo; String name; Student(int rollNo, String name){ this.rollNo = rollNo; this.name = name; } @Override public String toString() { return "[ " + this.rollNo + ", " + this.name + " ]"; } }
輸出
讓我們編譯並執行上述程式,這將產生以下結果:
Hash code: 368956094
java_util_vector.htm
廣告