Java의 HashMap에서 출력결과가 왜 이렇게 나오는 걸까요?

조회수 2274회
public class CHashMap {
    static HashMap<Integer, Student> student = new HashMap<Integer, Student>();

    public static void main(String[] args) {
        student.put(1111, new Student("김예시", "3학년", "영문과"));
        student.put(2222, new Student("정예시", "1학년", "영문과"));
        student.put(3333, new Student("김예시", "2학년", "컴공과"));
        student.put(4444, new Student("이예시", "4학년", "중문과"));
        student.put(5555, new Student("문예시", "4학년", "의예과"));

        printKey();
    }

    static public void printKey() {
        System.out.println("this is key----------");
        for(int key : student.keySet()) {
            System.out.println(key);
        }
    }
}

위의 결과가 5555 - 3333 - 1111 - 4444 - 2222 순서로 출력이 됩니다.

넣을 때의 순서대로 출력이 되야 하는게 아닌가요?

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)