Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I use Map class of Java to define a key->value set?

0
Posted

How do I use Map class of Java to define a key->value set?

0

A Map is an interface…it defines methods that any class that wants to implement a Map must use, but it doesn’t provide any concrete implementation for adding key value sets. You want to instantiate or extend one of the Java classes that implement the Map interface: Hashtable (a common one), HashMap, TreeMap, WeakHashMap, etc. Which one you use depends on your needs: some permit null entries (HashMap), some permit synchronization when working with multiple threads (HashMap), others don’t, some will result in sorted keys (TreeMap), etc. –> You get the point -> The Java API documentation provided in sources can give you more information on the different maps and help you determine which to use. Once you pick one, you simply create an instance of one of the provided classes, or the one you’ve extended… ie. Hashtable exTable = new HashTable(); and you can use the put and get methods to define(enter) key value sets, and retrieve them. ie. exTable.put(“eggs”,12); exTable.put(“bread”,1);

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123