Ads Sponsored By Google :)

Monday, 21 January 2013

map|map.entry|sortedmap interface|class methods in java collections|tutorial|example|api|5 hashmap and treemap|2 d collection frame work


map interface in java map interface methods in java map interface in java collections map interface in java tutorial map interface in java example map interface in java 6 map.entry class in java map.entry in java example map.entry in java api map.entry in java 5 map.entry in java  sortedmap interface java sortedmap interface example map sortedmap interface java 2 d collection frame work in java hashmap and treemap in java hashmap and treemap in java examples


   2-D Collection Frame Work :

                          2 – D collection frame work is also known as double collection frame work.

   Definition of 2 - D CollectionFrame Work :
                         A 2 – D Collection frame work is one in which the data is organized in single 
       variable in the form of key, value pair.
       
                                                      Or

                      A 2 – D collection frame work is one in which the data is the form of rows and  
    columns. In the key, value pair, the value of key must be unique and the value of value is 
    may or may not be unique. i.e : duplicates are permitted.
    
   In the key, value pair the values of both key and value are by default belongs to objects of 
   java.lang.Object.

2 – D Collection frame work / double / Map interfaces :
   1)      Java.util.Map
   2)      Java.util.Map.Entry
   3)      Java.util.SortedMap

         1)      Java.util.Map :
   
               Map is one of the pre defined interface present in the top most hierarchy of 2 – D 
        collection frame work interface.

         An object of Map interface allows us to organize the data in the form of key, value pair. 
     We know in the key, value pair the value of key represents unique and value of value  
     represents may or may not be unique.

        An object of Map interface always displays data in random order. i.e: in whatever order 
     we add the data to Map interface in the same order the data will be displayed.

     Methods in java.util.Map Interface :

1)      Public int size() :
              This method is used for finding the number of entries present in 2 – D collection frame work variable.

2)      Public Boolean isEmpty():
              This method returns true provided no entries are present in 2 – D collection frame work variable(Empty). This method returns false provided.

3)      Public Boolean put(Object kobj,Object vobj) :
              This method is used for adding and modifying the data to the 2 – D collection frame work variable. While we are suing put() method, if the value of key 
is not existing in 2 – D collection frame work variable then that corresponding key, value will be considered as inserted entry and this method returns true. While we 
are using put() method, if the value of key is already existing then the corresponding value of value will modified with new value of value and this will be considered as modified entry  and it returns false.

4)      Public object get(Object) :
              This method is used for obtaining value of value by passing value of key.
        For Example:
                      Object vobj=m.get(new Integer(10));
                      System.out.println(vobj);

5)      Public Set entrySet() :
             This  method is used for extracting the data from any 2 – D collection frame work variable and it will be holding in the object java.util.Set interface.
         For Example :
                  System.out.println(m);//{ (10 = 1.5), (20 = 2.5), (30=1.5)}
                  Set s=m.entrySet();
                  //s={ (10 = 1.5), (20 = 2.5), (30=1.5)}
                  Iterator itr=s.iterator();
                   While(itr.hasNext())
                  {
                       Object mobj=itr.next();
                       Map.Entry me=(Map.Entry)mobj;//object type casting
                      Object kobj=me.getKey();
                      Object vobj=me.getValue();
                      Integer io=(Integer)kobj;
                      Float fo=(Float)vobj;
                 }

6)      Public Set keyset() :
                  This method is used for obtaining or retrieving set of keys of any 2 – D collection frame work variable and pass the key.
For Example :
       //consider Set interface reference s such that it contains elements as key, value pairs.
       // (10,2.3), (20,2.1), (30,3.4)
       Set s=m.keySet();

           Java.util.Map.Entry:               
                    
                 In Map.Entry, Entry is one of the predefined class and map is one of the predefined 
         interface. The class Entry defined in Map interface and it can be accessed as Map.Entry.
         
                 The purpose of Map.Entry is to separate (key,value) pair from any 2 – D collection 
        frame work variable.

         Methods in Entry Class :

      1)      Public Object getkey()
      2)      Public object getValue()

   These methods are used for separating or obtaining the value’s of key and value from 
any 2 – D collection frame work variable.

3)      Java.util.SortedMap  :
    SortedMap is one of the sub interface of Map, so that all the methods of Map are inherited into SortedMap. An object of SortedMap also organizes the data in the form of (key,value) pair.
An object of SortedMap always displays the data in Sorted order. sorting process can be done  based on key. In older versions of java sorted map contain special methods except Map interface methods. Even though methods of Map and sortedmap are same, methods of map are defined into some predefined class in such way that the data is organized in the form of (key,value) pair and displayed in random order.
  In recent versions of java SortedMap is containing five special methods.
1)      Public Object first()
2)      Public Object Last()
3)      Public SortedMap headMap(Object kobj)
4)      Public SortedMap subMap(Object kobj1,Object kobj2)
5)      Pubic SortedMap tailMap(Object kobj)

   2 – D Collectionframe work classes :
        2 – D Collection frame work classes contains definition for those abstract methods which are inherited from 2 – D collection frame work interfaces.

  The following table gives 2 – D collection frame work interface name corresponding 2 – D collection frame work class name and their hierarchy.


2 - D Collection Frame Work Hierarchy



         From the above hierarchy we can observe that Classes which are under 2 - D collection 
      frame work  are as following 

        1) HashMap 
        2) TreeMap


 Data Extraction Interfaces are as follows :


          1- D and 2-D Collection Frame work classes are 
     


        To read the values dynamically from keyboard their is a class.
                 Java.util.Scanner or Scanner class



No comments:

Post a Comment

LinkWithin