0

I am creating a project in java. I have collected a source code.In a class there is a problem I can't understand. My code is:

import static java.lang.reflect.Array.set;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

class treemapcl{
    public static void main(String args[])
    {
        TreeMap tm=new TreeMap();
        tm.put("Ravi",new Double(345.35));
        tm.put("Raju",new Double(12.45));
        tm.put("Ram",new Double(90.25));

        Set s=tm.entrySet();
        Iterator i=set.iterator();

        while(i.hasNext()){
            Map.Entry m=(Map.Entry)i.next();
            System.out.print(m.getKey()+" ");
            System.out.println(m.getValue());
        }

        System.out.println();   
        double d=((Double)tm.get("Ravi")).doubleValue();
        tm.put("Ravi",new Double(d+100));
        System.out.println("new value of Ravi:"+tm.get("Ravi"));
    }
}

I am getting error in the line :

Iterator i=set.iterator();

It says

can't find symbol "set"

I am using Netbeans. What can I do to remove this error??

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • 2
    perhaps that why he sees a doctor, to know what is the symptoms – Baby Mar 28 '14 at 05:58
  • This post may help you [http://stackoverflow.com/questions/8689725/map-entry-how-to-use-it][1] [1]: http://stackoverflow.com/questions/8689725/map-entry-how-to-use-it – user2551549 Mar 28 '14 at 06:02

2 Answers2

6

Take a look at your decleration...

Set s=tm.entrySet();
    ^------------------

Then you use...

Iterator i=set.iterator();
           ^^^----------------

Try changing Set s=tm.entrySet(); to Set set=tm.entrySet();

I'd also recommend that you take a look at and use Code Conventions for the Java Programming Language

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • Really? Why would this attract a down vote? If I've done something wrong, please educate me so I can fix it and learn from it – MadProgrammer Sep 27 '15 at 20:35
3

In your code Iterator i=set.iterator(); the variable set is not defined, so make it

Iterator i=s.iterator(); and it will work.

Sreedhar GS
  • 2,694
  • 1
  • 24
  • 26