Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package lab6_fileReadWrite;
- import java.util.Enumeration;
- import java.util.Hashtable;
- /**
- *
- * @author acer
- */
- public class hashTableIntro {
- public static void main(String[] args) {
- Hashtable <String,String> stds=new Hashtable<String,String>();
- Hashtable <Integer,String> stds2;
- stds.put("One","A");
- stds.put("One", "newA");
- stds.put("Two", "B");
- System.out.println(stds);
- System.out.println("hash code is : "+stds.hashCode());
- System.out.println("------------GET----------");
- System.out.println("A's val "+stds.get("One"));
- System.out.println("if hash set contains newA "+stds.contains("newA"));
- Hashtable <Integer,String> stds1=new Hashtable<Integer,String>();
- System.out.println("------------CLEAR----------");
- stds1.put(1,"A");
- stds1.put(2, "B");
- stds1.put(3, "C");
- stds2 = (Hashtable<Integer, String>)stds1.clone();
- System.out.println("new set std1 "+stds1);
- stds1.clear();
- System.out.println("Empy after clear "+stds1);
- System.out.println("--------------------Contains val and key-------------");
- System.out.println("contains val newA "+stds.containsValue("newA"));
- System.out.println("contains key One "+stds.containsKey("One"));
- System.out.println("--------------------ToString-------------");
- System.out.println("String hashTable"+stds.toString());
- System.out.println("-------------------Clone-------------");
- System.out.println(stds.clone());
- System.out.println(stds2);
- System.out.println("------------Size of stds1 table----------");
- System.out.println("The size of the stds table is " +
- stds.size());
- System.out.println("The size of the STDS2 table is " +
- stds2.size());
- System.out.println("The size of the 'cleared' STDS1 table is " +
- stds1.size());
- System.out.println("--------------------KEYS-------------");
- Enumeration enu = stds.keys();
- System.out.println("The enumeration of keys are:");
- // Displaying the Enumeration
- while (enu.hasMoreElements()) {
- System.out.println(enu.nextElement());
- }
- System.out.println("------------Compute used for UPDATE--------------");
- Hashtable<String, Integer> table = new Hashtable<>();
- table.put("Pen", 10);
- table.put("Book", 500);
- table.put("Clothes", 400);
- table.put("Mobile", 5000);
- // print map details
- System.out.println("hashTable: " + table.toString());
- // remap the values of hashTable
- // using compute method
- table.compute("Pen", (key, val)
- -> val + 15);
- table.compute("Clothes", (key, val)
- -> val - 120);
- // print new mapping
- System.out.println("new hashTable: " + table);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement