Home » Core Java » util » Page 20

util

Get size of Hashtable example

This is an example of how to get the size of the Hashtable, that is the number of the key- value pairs that the Hashtable contains. Getting the size of the Hashtable implies that you should: Create a new Hashtable. Populate the hashtable with elements, using put(K key, V value) API method of Hashtable. Invoke the size() API method of ...

Read More »

Get Set view of Hashtable keys example

In this example we shall show you how to get a Set view of Hashtable keys. To get a Set view of Hashtable keys one should perform the following steps: Create a new Hashtable. Populate the hashtable with elements, using put(K key, V value) API method of Hashtable. Invoke keySet() API method of Hashtable. The method returns a Set that ...

Read More »

Get Collection view of Hashtable values example

With this example we are going to demonstrate how to get a Collection view of the Hashtable values. In short, to get a Collection view of the Hashtable values you should: Create a new Hashtable. Populate the hashtable with elements, using put(K key, V value) API method of Hashtable. Invoke values() API method of Hashtable. It returns a Collection that ...

Read More »

Copy all elements of Hashmap to Hashtable example

This is an example of how to copy all elements of a HashMap to a Hashtable. Coping HashMap elements to a Hashtable implies that you should: Create a new HashMap. Populate the hashmap with elements, using put(K key, V value) API method of HashMap. Create a new Hashtable. Populate the hashtable with elements, using put(K key, V value) API method ...

Read More »

Check value existence in Hashtable example

In this example we shall show you how to check a value existence in a Hashtable. The Hashtable API provides methods for such operations. To check if a value exists in a Hashtable one should perform the following steps: Create a new Hashtable. Populate the hashtable with elements, using put(K key, V value) API method of Hashtable. Invoke containsValue(Object value) ...

Read More »

Check key existence in Hashtable example

With this example we are going to demonstrate how to check a key existence in a Hashtable. In short, to check if a key exists in a Hashtable you should: Create a new Hashtable. Populate the hashtable with elements, using put(K key, V value) API method of Hashtable. Invoke the containsKey(Object key) API method of Hashtable, with a key as ...

Read More »

Vector Enumeration example

This is an example of how to obtain a Vector Enumeration in Java. Obtaining a Vector Enumeration implies that you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke elements() API method of Vector to get an Enumeration of the Vector’s elements. Enumerate through the elements of an Enumeration, with hasMoreElements(), ...

Read More »

Sort Vector example using Collections sort

In this example we shall show you how to sort the elements of a Vector, using the Collections API, and in particular the sort(List list) API method. To sort the elements of a Vector one should perform the following steps: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke the sort(List list) ...

Read More »

Set Vector size example

With this example we are going to demonstrate how to set the Vector size, that is setting a greater or less size than the current size of the Vector. In short, to set the Vector size you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke the setSize(int newSize) API method ...

Read More »

Search elements in Vector from index example

This is an example of how to search an element in a Vector from its index. Searching elements in a Vector from index implies that you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke indexOf(Object o, int index) API method of Vector. The method returns the index of the first ...

Read More »