Showing posts with label java hashset example. Show all posts
Showing posts with label java hashset example. Show all posts

Thursday, 11 June 2015

How to Search Value in Hashtable Java

import java.util.Hashtable;

public class HashTableSearchValue {
   
    public static void main(String[] args) {
       
        Hashtable<Integer,String> ht = new Hashtable<Integer,String>();
       
        /*
         * Maps the specified key to the specified
         * value in this hashtable
         */
        ht.put(1, "java");
        ht.put(2, "jersey");
        ht.put(3, "spring");
        ht.put(4, "c");
        ht.put(5, "php");
       
        System.out.println(" value=java ="+ht.containsValue("java"));
        System.out.println(" value=ankush ="+ht.containsValue("ankush"));
        System.out.println(" value=java ="+ht.containsValue("java"));
       
    }   
}

Output:

 value=java =true

 value=ankush =false

 value=java =true


Tuesday, 26 May 2015

How to create Hashset In Java

import java.util.HashSet;
import java.util.Set;

public class CreateHashset {
   
    public static void main(String[] args) {
       
        Set<String> hs = new HashSet<String>();
       
   
        hs.add("java");
        hs.add("php");
        hs.add("html");
        hs.add("javascript");
        hs.add("vb");
       
        //print hashset
        System.out.println("hashset = "+hs);
       
    }
}

Output:

hashset = [javascript, php, html, java, vb]

Java HashSet Examples