위치를 사용할 수 있는지 알려면 위치 관리자 클래스를 작성해야합니다. 이 테스트는 그냥 물론좌표를 저장하기위한 해시리스트를 구현하려면 어떤 종류의 데이터 구조가 필요합니까?
enter code here
public class PositionManager {
Hashtable currentPositions = new Hashtable();
void occupiedPosition(int x,int y){
this.currentPositions.put(new Integer("4"),new Integer("5"));
this.currentPositions.put(new Integer("1"),new Integer("5"));
this.currentPositions.put(new Integer("11"),new Integer("3"));
this.currentPositions.put(new Integer("42"),new Integer("55"));
this.currentPositions.put(new Integer("11"),new Integer("53"));
Set keys = this.currentPositions.keySet(); // The set of keys in the map.
Iterator keyIter = keys.iterator();
System.out.println("The map contains the following associations:");
while (keyIter.hasNext()) {
Object key = keyIter.next(); // Get the next key.
Object value = this.currentPositions.get(key); // Get the value for that key.
System.out.println(" (" + key + "," + value + ")");
}
}
public static void main(String[] args) {
new PositionManager().occupiedPosition(3, 3);
}
}
, 난 사용되는 모든 위치를 불러 오는되는 것을 시도하고있는 무슨, 문제는 내가 질수 있다는 것입니다 :
그래서이 시도 열쇠가 중복되어있다. 그래서 어떤 종류의 데이터 구조를 사용해야합니까? 사전에 감사합니다.
중복 키를 삽입하려는 시도가있을 때 구조가 어떻게 동작하게할까요? 새로운 키/값 쌍을 완전히 무시 하시겠습니까? 또는 이전 값을 새 값으로 바꿉니 까? – dharga