-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashTableExamples.java
48 lines (36 loc) · 1.5 KB
/
HashTableExamples.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.Hashtable;
public class HashTableExamples{
public static void main(String[] args) {
//Hashtable1<Integer,String> hashtable1 = new Hashtable<>();
//Hashtable1<Integer,String> hashtable2 = new Hashtable<>(10);
//Hashtable1<Integer,String> hashtable3 = new Hashtable<>(10,0.5f);
Hashtable<Integer,String> hashtable1 = new Hashtable<>();
hashtable1.put(100, "student1");
hashtable1.put(20, "student2");
hashtable1.put(3, "student3");
hashtable1.put(42, "student4");
hashtable1.put(42, "student5");
hashtable1.put(42, "student6");
hashtable1.remove(42);
int i = 1;
for(Integer key : hashtable1.keySet()){
System.out.print("key" + i + " = " + key + " ");
System.out.println("hashcode" + i + " = " + key.hashCode());
i++;
}
//integerlarin hashcode u kendisine esittir
System.out.println(hashtable1.keySet());
Hashtable<String,String> hashtable2 = new Hashtable<>();
hashtable2.put("97", "student1");
hashtable2.put("98", "student2");
hashtable2.put("99", "student3");
i = 1;
for(String key : hashtable2.keySet()){
System.out.print("key" + i + " = " + key + " ");
System.out.println("hashcode" + i + " = " + key.hashCode());
i++;
}
//stringlerin hashcode u kendisine esit degildir
System.out.println(hashtable2.keySet());
}
}