In: Computer Science
1.Discuss the Associative Arrays in C# and Java, with example, mention the different operations.
2.Is the size static or dynamic?
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
Most associate arrays, whether they are called dictionaries or maps or hash, are implemented using something called a hash table, and a hash table itself is a very important and useful data structure.
In Java, It has Map interface just as List was. It defines the operations for associative arrays, while HashMap and HashTable classes are implementations of these operations based on the hash table data structure.
HashTable is better when working with multi-threaded applications, where you have different threads accessing and changing this hash table, but it will add a performance cost.
ConcurrentHashMapclass is a replacement for the older HashTable.
There is also LinkedHashMap, which use linked list to iterate over the items in the same way they were inserted.
While TreeMap class also implements the Map interface, it’s actually a RedBlackTree, which is a self-balancing binary search tree.
C# also offers HashSet class which uses the hash table as in Java, while SortedSet is the sorted version.
import java.util.Hashtable;
Hashtable<String, String> capitals = new
Hashtable<String, String>();
capitals.put("United Kingdom", "London");
capitals.put("Spain", "Madrid");
capitals.put("Argentina", "Buenos Aires");
It is dynamic in nature.
Kindly revert for any queries
Thanks.