我有一个 Hashmap,我正在努力研究如何打印单个键和值。我可以打印所有这些,但想知道如何只打印其中一个谢谢
import java.util.HashMap;
public class Coordinate {
static class Coords {
int x;
int y;
public boolean equals(Object o) {
Coords c = (Coords) o;
return c.x == x && c.y == y;
}
public Coords(int x, int y) {
super();
this.x = x;
this.y = y;
}
public int hashCode() {
return new Integer(x + "0" + y);
}
public String toString()
{
return x + ";" + y;
}
}
public static void main(String args[]) {
HashMap<Coords, String> map = new HashMap<Coords, String>();
map.put(new Coords(65, 72), "Dan");
map.put(new Coords(68, 78), "Amn");
map.put(new Coords(675, 89), "Ann");
System.out.println(map.size());
System.out.println(map.toString());
}
}
此刻它显示
3
{65;72=Dan, 68;78=Amn, 675;89=Ann}
但希望它只是显示
65;72=Dan
谢谢你看