hashCode()2 10. [자바] HashSet이 중복값을 제거하지 못할 때 HashSet의 add메소드의 진실 HashSet의 add메소드는 새로운 요소를 추가하기 전에 기존 노드와 가튼 것인지 판별하기 위한 작업으로 추가하려는 노드의 eqauls()와 hashCode()를 호출하게 된다. equals()와 hashCode()의 부재 import java.util.HashSet; public class HashSetTest { public static void main(String[] args) { HashSet set = new HashSet(); set.add("123"); set.add("123"); set.add(new Person("KimJava", 100)); // ↓동일↓ set.add(new Person("KimJava", 100)); // ↑동일↑ System... 2021. 1. 4. 01-2. [자바] hashCode() - Object클래스 hashCode() 이 메서드는 해싱(hashing)기법에 사용되는 '해시함수(hash function)'을 구현한 것이다. 해싱은 다량의 데이터를 저장하고 검색하는 데 유요한 데이터관리기법이고 해시함수는 찾고자 하는 값을 입력하면, 그 값이 저장된 위치를 알려주는 해시코드(hash code)를 반환한다. public static void main(String[] args) { String str1 = new String("abc"); String str2 = new String("abc"); System.out.println(str1.equals(str2)); System.out.println(str1.hashCode()); // String의 hashCode();는 오버라딩 되어 있음 .. 2020. 12. 23. 이전 1 다음