KH CHO
@kiho81cho0124
Reviews Written
-
Average Rating
-
Posts
Q&A
Comparator interface๋ฅผ compareToIgnoreCase๋ก ๋ฉ์๋ ๋ ํผ๋ฐ์ค๋ก ๋ณ๊ฒฝ ๊ด๋ จ
๊ตฌ๊ธ๋ง์ ํด๋ณธ ๊ฒฐ๊ณผ ์ ๊ฐ ๊ฐ์ ๋ด์ฉ์์ '์์ ๊ฐ์ฒด์ ์ธ์คํด์ค ๋ฉ์๋ ์ฐธ์กฐ' ์ ๋ํ ์ดํด๋ฅผ ๋ค๋ฅธ '์คํํฑ ๋ฉ์๋ ์ฐธ์กฐ', 'ํน์ ๊ฐ๊ฒ์ ์ธ์คํด์ค ๋ฉ์๋ ์ฐธ์กฐ', '์์ฑ์ ์ฐธ์กฐ'์ ๊ฐ์ด ๋ฐฉ์์ผ๋ก ์ดํดํ์์ต๋๋ค. ํ๊ธฐ ๋งํฌ ์ฐธ๊ณ ๋ฅผํด์ ๋ค์ ๊ฐ์๋ฅผ ๋ณด๋ ์ดํด๊ฐ ๋์์ต๋๋ค. https://imcts.github.io/java-method-reference/ ์ฒซ ๋ฒ์งธ ํํ์์๋ ์ฒซ๋ฒ์งธ ํ๋ผ๋ฏธํฐ๊ฐ ๋ฉ์๋์ ์์ ์๊ฐ ๋๊ณ , ๋๋จธ์ง ํ๋ผ๋ฏธํฐ๋ ํด๋น ๋ฉ์๋๋ก ์ ๋ฌ ๋ฉ๋๋ค.ex) String::compareToIgnoreCase๋ (x, y) -> x.compareToIgnoreCase(y) ์ ๊ฐ์ต๋๋ค.
- 4
- 8
- 712
Q&A
Comparator interface๋ฅผ compareToIgnoreCase๋ก ๋ฉ์๋ ๋ ํผ๋ฐ์ค๋ก ๋ณ๊ฒฝ ๊ด๋ จ
sort์ ์ธ์ ํ์ ์ ํ์ธ ํ๋๋ฐ, public static T> void sort(T[] a, Comparatorsuper T> c) ์ Comparator๋ด์ abstract method๊ฐ int compare(T o1, T o2); ํ ๊ฐ๋ผ์ ํด๋น method๋ฅผ lambda๋ก ์นํํ๊ฒ (o1, o2) -> 0 ์ด๊ตฌ ์ฌ๊ธฐ์ parameter๊ฐ o1, o2 ๋๊ฐ ์ธ๋ฐ method reference๋ก ์นํ๋๋ compareToIgnoreCase๋ public int compareToIgnoreCase(String str) { return CASE_INSENSITIVE_ORDER.compare(this, str);} String ํ๊ฐ ์ ๋๋ค. ๊ทธ๋์ ์ด๊ฒ ์ด๋ป๊ฒ method reference๋ก ์นํ๋๋์ง ์ดํด๊ฐ ์ ์๊ฐ๋ค์..; compareToIgnore์์ ๊ตฌํ๋ CASE_INSENSITIVE_ORDER.compare(this, str); ๋ผ๋ฉด ์ดํด๊ฐ๋๋๋ฐ์.. ๊ฐ์๋ฅผ ๋ช๋ฒ ๋๋ ค ๋ดค๋๋ฐ๋ ์ ์ดํด๊ฐ ์๊ฐ์ ๋ค์ ํ๋ฒ ์ฌ์ญค๋ด ๋๋ค ^^;;; ํน์ ์ฐธ์กฐํ๋ ค๊ณ ํ๋ method ๋ด๋ถ์ this๋ฅผ ์ฌ์ฉํ๋ฉด ์ฐธ์กฐํ๋ ค๊ณ ํ๋ method์ param์ ์๊ธฐ ์์ ์ ๋ํ ํ์ ์ด ํ๋ ๋ ๋ค์ด๊ฐ๋ค๊ณ ์๊ฐํด์ผ ํ๋์?
- 4
- 8
- 712




