HashMap and HashTable Example
package com.demo;
import java.util.Hashtable;
public class HashExample {
public static void main(String[] args) {
Hashtable<String, Object> sample = new Hashtable<String, Object>();
sample.put("name", "namratha");
/*if(sample.contains("namratha"))
{
System.out.println("hello if block success ");
}
else
System.out.println("else block");*/
/* if(sample.containsKey("name"))
System.out.println("if block");
else
System.out.println("else block");*/
/*if(sample.containsValue("namratha"))
System.out.println("if block");
else
System.out.println("else block");*/
System.out.println("get value is "+sample.get("name"));
if(sample.get("name").equals("namratha"))
{
System.out.println("if block success");
}
else
System.out.println("else");
}
}
package com.demo;
import java.util.HashMap;
public class HashMapClass{
public static void main(String[] args) {
HashMap<String,String> sample = new HashMap<String, String>();
sample.put("name", "asher");
/*if(sample.containsKey("name"))
System.out.println("if block");
else
System.out.println("else block");*/
/* if(sample.containsValue("asher"))
System.out.println("if block");
else
System.out.println("else block");*/
if(sample.get("name").equals("asher"))
System.out.println("if block");
else
System.out.println("else block");
}
}
No comments:
Post a Comment