Results 1 to 2 of 2
  1. #1
    sathishvegeta is offline Member
    Join Date
    Feb 2013
    Posts
    20
    Rep Power
    0

    Default Compartator interface in TreeMaP

    XML Code:
    import java.util.*;
    class Maps1 implements Comparator
    {
     [B][I][U][QUOTE][QUOTE]  public int compare(Object o1,Object o2) 
    {
     Integer i1=(Integer)o1;
     Integer i2=(Integer)o2;
     return i1.compareTo(i2);
    }[/QUOTE][/QUOTE][/U][/I][/B]
    }
    class Maps
    {
    public static void main(String args[])
    {
    TreeMap Marklist = new TreeMap(new Maps1());	
    Marklist.put(98,"Arul");
    Marklist.put(65,"Arun");
    Marklist.put(54,"Ramu");
    Marklist.put(99,"Raju");
    Marklist.put(78,"Krish");
    Marklist.put(96,"Malik");
    Set set =Marklist.entrySet();
    Iterator itr= set.iterator();
    while(itr.hasNext())
    {
    Map.Entry s = (Map.Entry)itr.next();
    String value =(String)s.getValue();
    int key=(Integer)s.getKey();
    System.out.print(key+" "); 
    System.out.println(value);
    }
    }
    }
    I cant able to understand the above bolded area but i got an output, Can anyone explain it brief and clearly through the coding??

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Compartator interface in TreeMaP

    It compares two Integers.
    And inner tags (eg bold, italics, quote) don't work inside code tags.
    And it should be [code] tags [/code], not [html].
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Working with a TreeMap
    By überfuzz in forum New To Java
    Replies: 1
    Last Post: 09-15-2011, 05:38 PM
  2. TreeMap vs Map
    By alpdog14 in forum New To Java
    Replies: 5
    Last Post: 03-27-2011, 06:07 PM
  3. [JAVA] TreeMap
    By watle in forum Advanced Java
    Replies: 3
    Last Post: 03-16-2011, 05:39 PM
  4. Treemap's
    By Russo in forum New To Java
    Replies: 6
    Last Post: 10-11-2009, 01:13 AM
  5. How to use treemap
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •