<%@ page import="java.util.Map;" %>
<%@ page import ="java.util.Hashtable;" %>
<%@ page import ="java.util.HashMap;" %>
<%
int i,val;
val=0;
i=1;
String word = "abcdefghijklmnopqrstuvwxyz";
Map dictionary = new HashMap();
for(i=0;i<25;i++) {
dictionary.put(word.charAt(i), val + 1)
}
for(String key: dictionary.keySet())
out.println(key + ": " + dictionary.get(key));
%>
I got this error
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP
PWC6197: An error occurred at line: 5 in the jsp file: /quiz1/test.jsp PWC6199: Generated servlet error: incompatible types required: java.lang.String found: java.lang.Object
PWC6199: Generated servlet error: /test_jsp.java uses unchecked or unsafe operations.
PWC6199: Generated servlet error: Recompile with -Xlint:unchecked for details.
word.charAt(i)
return a char. So your key in the map is a char not a String. You should declare your Map with genericsMap<String,Integer> dictionary = new HashMap<String,Integer>()
– JensMap<Character, Integer>
. – Luiggi Mendoza