maps problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kirankumar1248
    New Member
    • Sep 2007
    • 1

    maps problem

    i write code like this


    [CODE=java]import java.util.*;

    class TreeMapDemo
    {
    public static void main(String[] args)
    {

    Map tm=new TreeMap();

    tm.put(" ravi " , new Double(23423.22 ));
    tm.put(" raja " , new Double(45454.33 ));
    tm.put(" anil " , new Double(77666.32 ));
    tm.put(" mega " , new Double(34342.55 ));
    tm.put(" giga " , new Double(98666.22 ));
    tm.put(" hecta " , new Double(-32.22));

    Set set=tm.entrySet ();

    Iterator i=set.iterator( );

    while(i.hasNext ())
    {
    Map.Entry me=(Map.Entry)i .next();
    System.out.prin tln(me.getKey() + " :");
    System.out.prin tln(me.getValue ());
    }
    System.out.prin tln();

    double balance=((Doubl e)tm.get("Kiran Kumar")).double Value();
    tm.put(" Kiran Kumar",new Double(balance + 1000));
    System.out.prin tln(" Kiran Kumar's new balance :" +
    tm.get("Kiran Kumar"));
    }
    }[/CODE]



    it will show some error at tm.put linesssssssssss sssssssssssssss ssss
    Last edited by Ganon11; Sep 7 '07, 01:21 PM. Reason: Please use the [CODE] tags provided.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by kirankumar1248
    i write code like this


    import java.util.*;

    class TreeMapDemo
    {
    public static void main(String[] args)
    {

    Map tm=new TreeMap();

    tm.put(" ravi " , new Double(23423.22 ));
    tm.put(" raja " , new Double(45454.33 ));
    tm.put(" anil " , new Double(77666.32 ));
    tm.put(" mega " , new Double(34342.55 ));
    tm.put(" giga " , new Double(98666.22 ));
    tm.put(" hecta " , new Double(-32.22));

    Set set=tm.entrySet ();

    Iterator i=set.iterator( );

    while(i.hasNext ())
    {
    Map.Entry me=(Map.Entry)i .next();
    System.out.prin tln(me.getKey() + " :");
    System.out.prin tln(me.getValue ());
    }
    System.out.prin tln();

    double balance=((Doubl e)tm.get("Kiran Kumar")).double Value();
    tm.put(" Kiran Kumar",new Double(balance + 1000));
    System.out.prin tln(" Kiran Kumar's new balance :" +
    tm.get("Kiran Kumar"));
    }
    }



    it will show some error at tm.put linesssssssssss sssssssssssssss ssss
    1.) Use code tags when posting code
    2.) That should compile fine (unless you compile with -Xlint) and probably throw a NullPointer Exception when you run it.
    3.) Your map is raw so calling put on it with strings as key should generate a warning on 1.5 or higher compilers.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by kirankumar1248
      it will show some error at tm.put linesssssssssss sssssssssssssss ssss
      Is it really too much trouble to tell us the *exact* error the compiler showed?
      Are we supposed to guess at it? Are we supposed to copy and paste your
      code and compile it ourselves just to understand what you're all about?

      Jos

      ps. what is 'linessssssssss sssssssssssssss sssss'? Keyboard got stuck?

      Comment

      Working...