Tuesday, 21 July 2020

HashTable, Properties, Dictionary Data Structure in Java Programming Language

                 In this post, we will see HashTable, Properties, Dictionary Data Structure in Java Programming Language

Watch this video to know about HashTable, Properties, Dictionary Data Structure in Java:




Watch on YouTube: https://www.youtube.com/watch?v=jwzg5BcCExI


Program Code: (HashTableProg.java) 


import java.util.*;
public class HashTableProg {

   public static void main(String args[]) {
     
      Hashtable cls = new Hashtable();
      Enumeration rollno;
      int r;

      cls.put(35,"Parag");
      cls.put(42,"Mayur");
      cls.put(51,"Manish");
      cls.put(60,"Sumit");
     
      rollno = cls.keys();
     
      while(rollno.hasMoreElements()) {
         r = (int) rollno.nextElement();
         System.out.println(r + ": " + cls.get(r));
      }       
      System.out.println();
     
      cls.put(51, "Ramesh");
      System.out.println("New Mapping for 51:"+ cls.get(51));
   }
}
  


Output:
parag@parag-Inspiron-N4010:~/Desktop/prog$ javac HashTableProg.java
Note: HashTableProg.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
parag@parag-Inspiron-N4010:~/Desktop/prog$ java HashTableProg
42: Mayur
51: Manish
60: Sumit
35: Parag

New Mapping for 51:Ramesh
 

Program Code: (PropProg.java) 


import java.util.*;
public class PropProg {

   public static void main(String args[]) {
     
      Properties cls = new Properties();
      Enumeration rollno;
      String r;

      cls.setProperty("Thirty Five","Parag");
      cls.setProperty("Forty Two","Mayur");
      cls.setProperty("Fifty One","Manish");
      cls.setProperty("Sixty","Sumit");
     
      rollno = cls.keys();
     
      while(rollno.hasMoreElements()) {
         r = (String) rollno.nextElement();
         System.out.println(r + ": " + cls.getProperty(r));
      }       
      System.out.println();
     
      cls.setProperty("Fifty One", "Ramesh");
      System.out.println("New Mapping for Fifty One:"+ cls.getProperty("Fifty One"));
   }
}
  


Output:
parag@parag-Inspiron-N4010:~/Desktop/prog$ javac PropProg.java
parag@parag-Inspiron-N4010:~/Desktop/prog$ java PropProg
Sixty: Sumit
Thirty Five: Parag
Fifty One: Manish
Forty Two: Mayur

New Mapping for Fifty One:Ramesh
  

No comments:

Post a comment