Results 1 to 5 of 5
Thread: HashMap usage
- 03-05-2009, 07:04 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 24
- Rep Power
- 0
HashMap usage
hi,
I have a doubt in HashMap usage. I am having a program in which HashMap is declared and few elements are added to it and based on the key it is giving the value stored in that key. While compiling it is giving the error at the declaration of HashMap. I referred complete reference as well as in net also. The syntax specified in in references is same as What syntax used in the program. But it is giving that ": is expected".
can u tell me how to declare a HashMap in a program.
<code>
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public final class TestHashMap
{
public static void main( String[] args )
{
HashMap<String, String> h = new HashMap<String, String>(149,0.75f);
h.put( "WA", "Washington" );
h.put( "NY", "New York" );
h.put( "RI", "Rhode Island" );
h.put( "BC", "British Columbia" );
String stateName = h.get( "NY" );
System.out.println( stateName );
System.out.println( "enumerate all the keys in the HashMap" );
}
}
</code>
- 03-05-2009, 08:32 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
That code looks OK - perhaps you could give the exact compiler message and say which line it is referring to.
- 03-05-2009, 11:57 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 24
- Rep Power
- 0
HashMap usage
TestHashMap.java:11: error: ':' expected.
HashMap<String, String> h = new HashMap<String, String>(149,0.75f);
^
1 error
at the point of declaration it is giving the error.
- 03-05-2009, 02:06 PM #4
That code compiles and runs fine (from DOS command prompt).
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 03-05-2009, 04:50 PM #5
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
Similar Threads
-
usage of Hashtable
By venu2807 in forum New To JavaReplies: 4Last Post: 01-27-2009, 03:36 AM -
Usage of HTTPS
By Sayed in forum Advanced JavaReplies: 8Last Post: 12-06-2008, 10:02 AM -
Need help with AST usage on Eclipse! Thanks!
By j_aquino314 in forum EclipseReplies: 0Last Post: 10-08-2008, 07:15 PM -
Integer Usage
By bluegreen7hi in forum New To JavaReplies: 11Last Post: 01-24-2008, 08:54 AM -
Comm API Usage
By hobbyist in forum New To JavaReplies: 0Last Post: 11-16-2007, 04:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks