You Can Become A
๋ฆ๊ฒ ์์ํด๋ ๋๊ตฌ๋ ์ง ๋ ธ๋ ฅํ๋ฉด ๊ฐ๋ฐ์๊ฐ ๋ ์ ์์ด์ !
Comparator
โ ๋๋ค์ ๋ฆฌํฉํ ๋ง ํ๊ธฐ (Comparator ์ถ์ฝ ์๋ฆฌ)
Comparator ๋๋ค์ ๋ฆฌํฉํ ๋ง ํด๋ณด๊ธฐ ๋ค์์ ์ค์ ๋ก ์๋ฐ ํ๋ก๊ทธ๋๋ฐ์์ ๋ฐฐ์ด์ ์ ๋ ฌ(sort) ํ ๋ ์ฌ์ฉ๋๋ Comparator ์ธํฐํ์ด์ค ์ฌ์ฉ ์์ ์ด๋ค. Apple ํด๋์ค๊ฐ ์๊ณ ์์ฑ์ ์ธ์๋ก ์ฌ๊ณผ์ ๋ฌด๊ฒ(weight)๊ฐ์ ๋ฐ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์คํ๋ถ์์ ๋ฐฐ์ด๋ก ์ฌ๊ณผ ๊ฐ์ฒด๋ฅผ ๋ด๊ณ , ์ฌ๊ณผ ๋ฌด๊ฒ์ ๋ฐ๋ผ ๋ฐฐ์ด ์์๋ค์ ์ ๋ ฌํ๋ ค๊ณ ํ๋ค. ์ด๋ฅผ ์ฝ๋๋ก ๊ตฌํํ๋ฉด ์๋์ ๊ฐ์ด ๊ตฌํํ ์ ์๋ค. class Apple { private final int weight; // ์ฌ๊ณผ ๋ฌด๊ฒ public Apple(int weight) { this.weight = weight; } public int getWeight() { return weight; } @Override public String toString() { ret..