Skip to main content

HashMap in Java

    -What is HashMap:

      A HashMap has value and  key. store value based on Key. HasMap implements the Map interface and extends AbstractMap class.
      Allow only one null as key and can contain   multiple null value.
      Also Conatin Order of element.


        HasMap----extend---->AbstractMap----implement---->Map
       
        Now we see how to Put and Retrive value from HashMap.
       
       Example.

            import java.util.*;
              class MapTest{
                       public static void main(String args[]){
 
  HashMap<Integer,String> map=new HashMap<Integer,String>();
 
  map.put(1,"vjp");
  map.put(13,"Vasant");
  map.put(10,"anil");
 
  for(Map.Entry m:map.entrySet()){
  System.out.println(m.getKey()+" "+m.getValue());
  }
  }
}

 

        -How Internally Working.

     Example.







Comments

Post a Comment

Popular posts from this blog

Interface in Java

Interface:          An interface is a nothing but  reference type,it is same as class.In short Interface is collection of Abstract Method .          It can  also contain  final, static fields  .               you can't create object of Interface.    it can't have Constructor.   Interface can't implement another interface it can extend another one. Interface not extended by class but implemented. Declare Interface: public interface Example {     // final, static fields  .     //Method } Example 1.create interface that contain method. public interface IA {     public void show(); } 2.implement by class  public class ClassA  implements IA{     @Override     public void show() {         System.out.println("from class A called");   ...

What is java 8

What is java 8?  Java 8   is a major release of java development.  Java 8 initial version  was released on 18 march 2014.  Java 8 changes are done both at JVM and compiler level.  Java 8 provide following feature:              1)support functional  programing language. 2)new java script engine. 3)new date time api. 4)new streaming api. 5) Lambda expression. 6)  support Default method implementation. 7) support  Method reference.

Factory Pattern

Factory Pattern        Factory Pattern is way to create object in such Way using Common Interface  without exposing the creation logic Simple Example       Example: step  1.  creation of interface.     public interface BANK {        double getIntrest();   } step  2.  implementation of interface for BOB. public class BOB implements BANK {     @Override     public double getIntrest() {         return 8.7;     } } step 3.  implementation of interface for SBI . public class SBI implements BANK{     @Override     public double getIntrest() {         return 5.7;     }      } step 4.  implementation of interface for UNION  . public class UNION  implements BANK{     ...