Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,924 questions

51,857 answers

573 users

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

1 answer 152 views
1 answer 116 views
116 views asked Apr 29, 2020 by avibootz
2 answers 159 views
159 views asked Apr 29, 2020 by avibootz
1 answer 117 views
117 views asked Apr 28, 2020 by avibootz
1 answer 93 views
...