• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compilation error while using Map.

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?


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){}
}
}
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This code will compile only with JDK 1.5 or later; try

javac -version

to make sure you're using an appropriate compiler.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also,

If you're compiling this from within an IDE you can also look for compiler compliance settings.

I know in Eclipse you can set the compiler to conform to a lower version of Java than what your system is using.
 
reply
    Bookmark Topic Watch Topic
  • New Topic