这个 JAVAutil。矢量 .hashCode() 方法用于获取该向量的哈希代码值。
null
语法:
Vector.hashCode()
参数: 该方法不接受任何参数。
返回值: 该方法返回 散列码值 这个向量是整型的。
下面的程序演示了Java。util。矢量。hashCode()方法:
项目1: 带有字符串元素的向量。
// Java code to illustrate hashCode() import java.util.*; public class VectorDemo { public static void main(String args[]) { // Creating an empty Vector Vector<String> vec_tor = new Vector<String>(); // Use add() method to add elements into the Vector vec_tor.add( "Welcome" ); vec_tor.add( "To" ); vec_tor.add( "Geeks" ); vec_tor.add( "4" ); vec_tor.add( "Geeks" ); // Displaying the Vector System.out.println( "Vector: " + vec_tor); // Displaying the hashCode value of Vector System.out.println( "The hashCode value is: " + vec_tor.hashCode()); } } |
输出:
Vector: [Welcome, To, Geeks, 4, Geeks] The hashCode value is: -878886256
项目2: 带有整数元素的向量。
// Java code to illustrate hashCode() import java.util.*; public class VectorDemo { public static void main(String args[]) { // Creating an empty Vector Vector<Integer> vec_tor = new Vector<Integer>(); // Use add() method to add elements into the Vector vec_tor.add( 10 ); vec_tor.add( 20 ); vec_tor.add( 30 ); vec_tor.add( 40 ); vec_tor.add( 50 ); // Displaying the Vector System.out.println( "Vector: " + vec_tor); // Displaying the hashCode value of Vector System.out.println( "The hashCode value is: " + vec_tor.hashCode()); } } |
输出:
Vector: [10, 20, 30, 40, 50] The hashCode value is: 38490301
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END