Ads Sponsored By Google :)

Tuesday, 22 January 2013

difference|between Treemap and|vs hashmap|treeset example for|in java|6 collection with comparator|iterate|tutorial|api|speed


Treemap in java Treemap example in java Treemap in java example Treemap in java 6 Treemap in java tutorial Treemap api in java Treemap example in java collection Treemap example in java with comparator
difference between hashmap and treemap difference between treeset and treemap difference between hashmap and treemap in java difference between treeset and treemap in java difference hashmap and treemap in java treemap vs hashmap in java treemap vs hashmap in java performance example program for treemap in java iterate treemap in java example example for treemap in java java collection treemap vs hashmap speed


    TreeMap :

         1)      TreeMap object organizes the data in the form of (key, value) pairs, where keys are              
                  distinct.
         2)      TreeMap follows Binary Tree’s concept for organizing the data in the form of (key, value) 
                   pair.
         3)      TreeMap object displays the data in sorted order.
         4)      The operations like insertion / deletion  and modification are taking less amount of time.
         5)      Retrieval time of hashmap is fast / less.
         6)      Creating the TreeMap is nothing but creating the object of TreeMap class.
         
              Ex : TreeMap hm=new TreeMap();

           Methods in TreeMap which are inherited from Map and SortedMap interfaces. To know 
        about methods in details refer 2 - D Collectionframe work

       Difference between TreeMap and HashMap ?

        Both TreeMap and HashMap are having methods which are inherited from Map interface.
      And these are allows to organizes the data in the form of (key, value) pair belongs 2 – D 
     collectionframe work.
   
        TreeMap Functionality is depends on binary Tree Concept. TreeMap object displays the 
     data in sorted order by implementing SortedMap interface. Insertion, deletion and   
     modification are taking less amount of time. Retrieval time of hashmap is fast or less.  
     
       HashMap Functionality is depends on Hashing Mechanism Concept. HashMap object   
    displays the data in Random order.  Insertion, deletion and modification are takes more  
    amount of time. Retrieval time of hashmap is very slow.

     Difference between TreeMap and TreeSet ?

        Both TreeMap and TreeSet Classes functionality are similar. They differ in TreeMap 
   belongs to 2 – D collection frame work, TreeSet belongs to 1 – D Collection frame work.

    The Following Program illustrate the concept of TreeMap with Iterator Interface :


         import java.util*;
         class tm
       {
         Public static void main(String args[])
        {
          TreeMap tm=new TreeMap();
          System.out.println(“Content of tm “+tm);
          System.out.println(“size of tm “+tm.size());
         //add the data to 2 –D CFW
         hm.put(new Integer(10),new Float(1.5f));
         hm.put(new Integer(100),new Float(2.5f));
         hm.put(new Integer(1),new Float(4.5f));
         hm.put(new Integer(90),new Float(11.5f));
        System.out.println(“Content of tm”+tm);
        System.out.println(“Size of tm”+tm.size());
       // extract the data from 2 –D CFW
        System.out.println(“Extract the data from  hm from enrtySet()àSetà iterator”);
        Set s=new tm.entrySet();
        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;
        }
       System.out.println(“extract the data from htàkeySet()àSetàtoArray()”);
       Set st=tm.keySet();
       Object kobj1[]=st.toArray();
        for(int i=0;i<kobj1.length;i++)
       {
         Object vobj1=tm.get(kobj1[i]);
         Integer io1=(Integer)kobj1[1]);
         Float fo1=(Float)vobj1;
         int acno1=io1.intValue();
         float bal1=io1.floatValue();
         }
       }
      }

    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