1:25 am - Wednesday January 25, 2017

Archive: Java Examples Subscribe to Java Examples

Check whether a key is avilable in Hashtable boolean containsKey(Objectkey)

BACK                                   This method returns true if the specified object is a key in the hashtable, otherwise returns false . Example Program import java.util.Hashtable; public class HashtableContainsKey...

Check whether a value is present in hashtable boolean contains(Object value)

  BACK                           This function returns  true if the key maps to the value argument in the hashtable.Otherwise it returns false . Example Program import java.util.Hashtable; public class HashtableContains...

HashTable example programs and Tutorial in java

BACK 1.Check whether a value is present in hashtable  boolean contains(Object value) 2.Check whether a key is avilable in Hashtable boolean containsKey(Objectkey) 3.Convert hashtable keys to Set Set<k> keySet() 4.Retrieve all values...

Remove Capacity of a vector void trimToSize()

BACK                          The trimToSize() method is used to trim the capacity of this vector to be the vector’s current size. If the capacity of this vector is larger than its current size,  then the capacity is changed...

Add element to the specified position in vector void add(int index,E element)

BACK                                           This add(int index,E element) method is used to Insert the specified element (E) at the specified position (index) in the list.It shift next element  to...

Retrieve a HashCode of a Vector int hashCode( )

BACK                                     The hashCode() method is used to return the hash code value for this Vector. Example program import java.util.Vector; public class VectorHashCode { public...

Replace an element present in a Vector E set(int index, E element)

BACK                     The public E set(int index, E element) method Replaces the element at the specified position in this Vector with the specified element. Example program import java.util.Vector; public class VectorSet...

Remove an element from the Vector E remove(int index)

BACK                                          The remove(int index) method is used to remove the specific element in the vector.It shift upcomeing element  to the left (subtracts one from their indices)....

Add an element to a Vector boolean add(E e)

BACK                                   The public boolean add(E e) method Include the specified element to the end of  vector(e-element to be added to this vector). Example program import java.util.Vector; public...

Verify LinkedHashMap is Empty boolean isEmpty()

BACK                               The method public boolean isEmpty() checks whether the map is empty or not. If the map is empty it returns true,Otherwise it returns false. Example Program import java.util.LinkedHashMap; public...

Remove key value pair from LinkedHashMap V remove(Object key)

BACK                                                   The method public V remove(Object key) removes the particular key from the linkedhashMap,if the key is present. After performing the remove()...

Create a copy of LinkedHashMap Object clone()

BACK                                  The method public Object clone () displays the copy of the elements present in the linkedhashmap.The cloned Map looks same as that of the actual map.The elements themselves...

Search for given value in LinkedHashMap boolean ContainsValue(Object value)

BACK                               The method boolean ContainsValue(Object value) checks whether the value is present in the map. If the value present in the map ,it returns true.Otherwise it returns false. Example...

Add all key value pair from another Map void putAll(Map m)

BACK                                                       The method public void putAll(Map<?extends K,?extends V>m) copies all the mappings from one map to another map. The function...

Add key value pair to LinkedHashMap V put(K key, V value)

BACK                 The method public V put(K key,V value ) assigns the value with the specified key in the map. Also if a map previously contains a value for the key, the old value is replaced. Example Program import java.util.Iterator; import...

Check whether a given key is available in LinkedHashMap boolean

BACK                                           The method public boolean containsKey(Object key) returns true if the map contains the mappings of the specified key. If there is no mappings for the specified...

Retrieve value of given Key in LinkedHashMap V get(Object key)

BACK                             The method public V get(Object key) returns a value to which the key is mapped. It returns null if there is no mapping for the given key. Example Program import java.util.LinkedHashMap; public...

Clear all elements from LinkedHashMap void Clear()

BACK                            The method void clear() clears all the elements from the map. After performing the clear() function the map returns no values . Example Program import java.util.LinkedHashMap; public...

Fetch all keys from a LinkedHashMap Set keySet()

BACK                                                     The method public set<k>keyset() returns a view of the elements present in the set. Incase of removing an element from the set,keyset.remove(k)...

Vector example programs and Tutorial in java

BACK 1.Add an element to a Vector boolean add(E e) 2.Remove an element from the Vector E remove(int index) 3.Replace an element present in a Vector E set(int index, E element) 4.Retrieve a HashCode of a Vector int hashCode( ) 5.Add element...