How to add a new value to Hashtable in Java

1 Answer

0 votes
import java.util.Hashtable;

public class Main {
    public static void main(String[] args) {
        // Create a Hashtable instance
        Hashtable<String, Integer> hashtable = new Hashtable<>();

        // Add key-value pairs to the Hashtable
        hashtable.put("Mr. Bean", 10);
        hashtable.put("Mrs. Bean", 20);
        hashtable.put("Uncle Bean", 30);
        hashtable.put("Aunt Bean ", 40);

        System.out.println(hashtable);
    }
}


 
/*
run:
     
{Uncle Bean=30, Mr. Bean=10, Aunt Bean =40, Mrs. Bean=20}
     
*/

 



answered Feb 28, 2025 by avibootz

Related questions

...