HashMap in java ?

private HashMap map = new HashMap<String,Integer>();

public void put(String name, int value){ map.put("Ru lu ",90); }

public Set getNames() {

return map.keySet();

}

}

public static void main(String[] args)

{

NumberNames n = new NumberNames();

}

}

output :

D:\>javac NumberNames.java

NumberNames.java:4: illegal start of expression

private HashMap map = new HashMap<String,Integer>();

^

NumberNames.java:5: illegal start of expression

public void put(String name, int value){ map.put("Ru lu ",90); }

^

NumberNames.java:9: ';' expected

}

^

3 errors

[702 byte] By [Tatona] at [2007-10-3 3:04:36]
# 1
You need to provide more code (using [code] tags) because I don't think the code you provided is the source of your problem.P.S. There are other more minor problems but get this major problem fixed first.
sabre150a at 2007-7-14 20:54:38 > top of Java-index,Java Essentials,New To Java...
# 2

> You need to provide more code (using [code] tags)

> because I don't think the code you provided is the

> source of your problem.

>

> P.S. There are other more minor problems but get this

> major problem fixed first.

public NumberNames() {

private HashMap map = new HashMap<String,Integer>();

public void put(String name, int value){ map.put(chuchu, 9); }

public Set getNames() {

return map.keySet();

}

}

public static void main(String[] args)

{

NumberNames n = new NumberNames();

}

}

Tatona at 2007-7-14 20:54:38 > top of Java-index,Java Essentials,New To Java...
# 3

import java.util.*;

public class NumberNames

{

private HashMap<String,Integer> map = new HashMap<String,Integer>();

public NumberNames()

{

}

public void put(String name, int value)

{

map.put(name, value);

}

public Set getNames()

{

return map.keySet();

}

public static void main(String[] args)

{

NumberNames n = new NumberNames();

}

}

Message was edited by:

sabre150

sabre150a at 2007-7-14 20:54:38 > top of Java-index,Java Essentials,New To Java...
# 4

import java.util.*;

public class NumberNames

{

private HashMap<String,Integer> map = new HashMap<String,Integer>();

/*public NumberNames()

{

}*/

public void put(String name, int value)

{

map.put(name, value);

}

public Set getNames()

{

return map.keySet();

}

public static void main(String[] args)

{

NumberNames n = new NumberNames();

}

}

Tatona at 2007-7-14 20:54:38 > top of Java-index,Java Essentials,New To Java...
# 5
I assume that you will add to the class so why take out the default constructor when you will almost certainly need it later!
sabre150a at 2007-7-14 20:54:38 > top of Java-index,Java Essentials,New To Java...
# 6
because it's not needed now.Empty methods smell of bad design.
jwentinga at 2007-7-14 20:54:38 > top of Java-index,Java Essentials,New To Java...
# 7
> because it's not needed now.> Empty methods smell of bad design.A little too general for my taste.
sabre150a at 2007-7-14 20:54:38 > top of Java-index,Java Essentials,New To Java...
# 8
Sabre is right. But my point was that it is not compulsary
Tatona at 2007-7-14 20:54:38 > top of Java-index,Java Essentials,New To Java...