Hashtable:
- A Hashtable is an array of list. Each list is known as a bucket. A Hashtable contains values based on the key.
- It contains only unique elements.
- It may have not have any null key or value.
- It is synchronized.
- import java.util.*;
- public class HashTableDemo {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Hashtable<Integer, String>htable=new Hashtable<>();
- htable.put(100, "Sujan");
- htable.put(103, "Shakil");
- htable.put(102, "Shimul");
- htable.put(104, "Badhon");
- print(htable);
- htable.remove(104);
- System.out.println("\nAfter removing:");
- print(htable);
- htable.replace(100, "Hasan Sujan");
- htable.replace(102, "Hossain Shimul");
- System.out.println("\nAfter replacing:");
- print(htable);
- }
- public static void print(Hashtable<Integer, String>hashtable) {
- for(Map.Entry m:hashtable.entrySet()){
- System.out.println(m.getKey()+" "+m.getValue());
- }
- }
- }
0 Comments:
Post a Comment