Check key & Value existence in Hashtable example – Java

by Chaitanya Singh July 9, 2014

Example In this example we are gonna see how to check Key and value existence in Hashtable. We will be using following two methods to perform this check: containsKey(Object key): To check if the key present in Hashtable. containsvalue(Object value): To check if the value present in Hashtable. import java.util.Hashtable; public class CheckKeyValueExample { public static void main(String[] args) { […]

Read the full article →

Get size of Hashtable example in Java

by Chaitanya Singh July 9, 2014

Example In this example we are gonna see how to get the size of Hashtable. We will be using size() method of Hashtable class to perform this operation. import java.util.Hashtable; public class SizeExample{ public static void main(String[] args) { // Creating a Hashtable instance Hashtable<String, String> hashtable = new Hashtable<String, String>(); // Adding key-value pairs to Hashtable hashtable.put("A", "Apple"); hashtable.put("B", […]

Read the full article →

Hashtable Iterator example – Java

by Chaitanya Singh July 9, 2014

In this example we will see how to iterate a Hashtable using Iterator. Using Iterator we can display Hashtable key and value separately for each pair of elements. Example There are several methods (of both Hashtable class and Iterator interface) used in the below program. Definition and description of each method have been provided in the comment sections of the […]

Read the full article →

Hashtable in java with example

by Chaitanya Singh July 8, 2014

In the previous tutorial we learnt about HashMap which is used for storing key and value pairs. Hashtable is similar to HashMap but it is synchronized. There are few more differences between HashMap and Hashtable class, you can read them in detail at: Difference between HashMap and Hashtable. In this tutorial we will see how to create a Hashtable, how […]

Read the full article →

Remove all mappings from Hashtable example – Java

by Chaitanya Singh July 8, 2014

In the last tutorial we have seen how to remove a mapping from Hashtable based on key. In this tutorial we will learn how to remove all the mappings from Hashtable and make it empty. Example Method used in the below program: clear() public void clear(): Clears this hashtable so that it contains no keys. import java.util.Hashtable; public class RemoveAllExample […]

Read the full article →

Remove mapping from Hashtable example – Java

by Chaitanya Singh July 8, 2014

In this tutorial we are gonna see how to remove a key-value mapping from Hashtable. We will be using remove(Object key) method of Hashtable class. Example Method used in the below program is: public V remove(Object key): Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is not in the hashtable. import […]

Read the full article →

Java – Check if a particular key exists in HashMap example

by Chaitanya Singh July 8, 2014

In the last tutorial we learnt how to check whether a particular value exists in HashMap. In this example we are gonna see how to check if a particular key is present in HashMap. We will be using containsKey() method of HashMap class to perform this check. The method definition and description are as follows: public boolean containsKey(Object key): Returns […]

Read the full article →

Java – Check if a particular value exists in HashMap example

by Chaitanya Singh July 8, 2014

In this example we are checking whether a particular value exists in HashMap or not. We will be using containsValue() method of HashMap class to perform this check: public boolean containsValue(Object value): Returns true if this map maps one or more keys to the specified value. Complete Code: Here we have a HashMap of integer keys and String values, we […]

Read the full article →

Java – Get size of HashMap example

by Chaitanya Singh July 7, 2014

In this example we are gonna see how to get the size of HashMap using size() method of HashMap class. Method definition and description are as follows: public int size(): Returns the number of key-value mappings in this map. import java.util.HashMap; public class SizeExample { public static void main(String[] args) { // Creating a HashMap of int keys and String […]

Read the full article →

Java – HashMap Iterator example

by Chaitanya Singh July 7, 2014

Example In the previous tutorial we have seen different-2 ways to iterate a HashMap. In this example we are gonna see how to iterate a HashMap using Iterator and display key and value pairs. The steps we followed in the below example are as follows: 1) Create a HashMap and populate it with key-value pairs. 2) Get the Set of […]

Read the full article →

Java – Remove all mappings from HashMap example

by Chaitanya Singh July 7, 2014

Example In the last tutorial we shared how to remove a specific mapping from HashMap based on key. In this example we are going to see how to remove all the mappings from HashMap. We will be using clear() method of HashMap class to do this: public void clear(): Removes all of the mappings from this map. The map will […]

Read the full article →

Our Friend's website link : FromDev.com