Tuesday, 3 March 2015

Java : Collection Framework : Hashtable (PutReturn)


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=peq4Hp5Z0e8&list=UUhwKlOVR041tngjerWxVccw

HashtableExample.java
import java.util.Hashtable;

/*
 * Example of put(K key,V value) method.
 */
public class HashtableExample
{
    public static void main(String[] args)
    {

        Hashtable<String, String> hashtable = new Hashtable<String, String>();

        /*
         * Key = CountryCode,Value = CountryName.
         * 
         * Maps the specified key to the specified value in this hashtable.
         * 
         * Neither the key nor the value can be null. The value can be retrieved
         * by calling the get method with a key that is equal to the original
         * key.
         * 
         * Returns: the previous value of the specified key in this hashtable,
         * or null if it did not have one
         */
        String value = hashtable.put("AF", "AFGHAN");

        System.out.println("hashtable : " + hashtable);

        System.out.println("Previous value associated with key 'AF' : " + value
                + "\n");

        value = hashtable.put("AF", "AFGHANISTAN");

        System.out.println("hashtable : " + hashtable);

        System.out
                .println("Previous value associated with key 'AF' : " + value);

    }
}
Output
hashtable : {AF=AFGHAN}
Previous value associated with key 'AF' : null

hashtable : {AF=AFGHANISTAN}
Previous value associated with key 'AF' : AFGHAN
To Download HashtableDemoPutReturn Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/HashtableDemoPutReturn.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge