aspose file tools*
The moose likes Java in General and the fly likes Compilation error while using Map. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Compilation error while using Map." Watch "Compilation error while using Map." New topic
Author

Compilation error while using Map.

krishna pradeep
Greenhorn

Joined: May 24, 2006
Posts: 25
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){}
}
}


Pradeep<br /> <br />SCJP 1.4, SCWCD 1.4 , SCBCD 1.3
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi,

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

javac -version

to make sure you're using an appropriate compiler.


[Jess in Action][AskingGoodQuestions]
Seamus Minogue
Ranch Hand

Joined: Jun 24, 2008
Posts: 41
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compilation error while using Map.