ハッシュマップがあり、単一のキーと値を出力する方法に苦労しています。私はそれらすべてを印刷することができますが、それらの1つだけを印刷する方法を知りたいですありがとう
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
見てくれてありがとう