Advertisement

07.05.2008 at 03:10PM PDT, ID: 23541076
[x]
Attachment Details

Compilation error in the line  Map<Integer, String> map = new HashMap<Integer, String>();

Asked by saji27 in Java Programming Language

Tags: Java

I am getting below error message while compiling the program.

java.lang.Error: Unresolved compilation problems:
      Syntax error on token "<", ( expected
      Syntax error, insert ")" to complete Expression
      Syntax error on token "<", ( expected
      Syntax error on token "(", invalid Expression

Even i tried to compile it in JDK 5.0 but no use. Can someone help me ?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
import java.util.*;
 
public class MapDemo {
  public static void main(String args[]) { 
    String days[]={"Sunday", "Monday", "Tuesday", "Wednesnday",
                         "Thursday", "Friday", "Saturday"};
    Map<Integer, String> map = new HashMap<Integer, String>();
 
  try{
  for(int i=0; i<7; i++){
    map.put(i, days[i]);
  }
  
  TreeMap tMap=new TreeMap(map);
     //Rerieving all keys
    System.out.println("Keys of tree map: " + tMap.keySet());
    //Rerieving all values
    System.out.println("Values of tree map: " + tMap.values());
    //Rerieving the First key and its value
    System.out.println("First key: " + tMap.firstKey() + 
                  " Value: " + tMap.get(tMap.firstKey()) + "\n");
      
    //Removing the first key and value
    System.out.println("Removing first data: " 
                          + tMap.remove(tMap.firstKey()));
    System.out.println("Now the tree map Keys: " + tMap.keySet());
    System.out.println("Now the tree map contain: " + tMap.values() + "\n");
    //Rerieving the Last key and value
    System.out.println("Last key: " + tMap.lastKey() + 
                       " Value: " + tMap.get(tMap.lastKey()) + "\n");  
    //Removing the last key and value
    System.out.println("Removing last data: " + tMap.remove(tMap.lastKey()));
    System.out.println("Now the tree map Keys: " + tMap.keySet());
    System.out.println("Now the tree map contain: " + tMap.values());
  }
  catch(Exception e){}
  }
}
 
Loading Advertisement...
 
[+][-]07.05.2008 at 07:16PM PDT, ID: 21939084

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: Java
Sign Up Now!
Solution Provided By: objects
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.05.2008 at 07:17PM PDT, ID: 21939087

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628