Ich verstehe das Problem nicht so richtig. Du möchtest einer anderen Klasse die HashMap im Konstruktor übergebe und dann mit den Werten arbeiten? Also sowas:
[code=Java]
import java.util.HashMap;
import java.util.Map;
public class HM {
private HashMap<String, String> test = new HashMap<String, String>();
public HM() {
test.put("bla", "x");
test.put("blub", "y");
}
public HashMap<String, String> getTestMap() {
return test;
}
public static void main(String[] args) {
new PrintMapValues(new HM().getTestMap()).printValues();
}
}
class PrintMapValues {
Map<String, String> map;
public PrintMapValues(Map<String, String> map) {
this.map = map;
}
public void printValues() {
// Hole Objekt mit Hilfe von Key
System.out.println(map.get("bla"));
// Gib alle Key:Value Paare aus
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
System.out.println("Key: " + key + "\tValue: " + value);
}
}
}[/code]