"getFirst()"및 "getSecond()"두 가지 방법을 사용하는 IntPair 클래스가 있습니다. 현재이 방법을 사용하고있는 동안 "hashMap j"에 특정 값이 들어 있는지 확인한 다음 작업을 수행하려고합니다.HashMap <Object, String> 값 확인
Object obj = j.values();
t.moveCursor(((IntPair)obj).getFirst(), ((IntPair)obj).getSecond());
내가 개체로 확인 캐스팅거야 경우 나도 몰라, 또는 첫 번째 줄에 "개체 OBJ = j.values는()"를 교체 할 필요가있는 경우 : 나는이 라인에 문제가 있다고 생각 다른 메소드 호출로. j.containsValue ("0") 다음에 System.out.print ("Message")를 사용하여 테스트 한 결과 메시지가 다시 나타납니다.
이것은 작동시키기 위해 노력하는 방법의 일부입니다.
public static HashMap<IntPair, String> j = new HashMap<>();
j.put(new IntPair(firstInt, secondInt), value);
if (j.containsValue("0"))
{
Object obj = j.values();
t.moveCursor(((IntPair)obj).getFirst(), ((IntPair)obj).getSecond());
t.putCharacter('x');
}
else if (j.containsValue("1"))
{
Object obj = j.values();
t.moveCursor(((IntPair)obj).getFirst(), ((IntPair)obj).getSecond());
t.putCharacter('v');
}
IntPair 클래스 : 어떤 도움이 정말 감사하겠습니다
public class IntPair {
private final int first;
private final int second;
public IntPair(int first, int second) {
this.first = first;
this.second = second;
}
@Override
public int hashCode() {
int hash = 3;
hash = 89 * hash + this.first;
hash = 89 * hash + this.second;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final IntPair other = (IntPair) obj;
if (this.first != other.first) {
return false;
}
if (this.second != other.second) {
return false;
}
return true;
}
public int getFirst() {
return first;
}
public int getSecond() {
return second;
}
}
. 고맙습니다!
일을 할 수있는 작은 프로그램을 작성했습니다 방법 ... ". 2) IntPair 클래스가 equals와 hashCode()를 적절히 오버 라이딩한다고 가정합니다. 3) 정확히 무엇이 요구되는지, 또는 당신이 붙어 있는지 확실하지 않습니다. 전송에 관한 질문을 언급합니다. 오류 또는 예외를 발생시키려는 시도입니까? –