โ์คํธ๋ฆผ์ด๋ผ๋ ๊ฒ์ด ๋ฌด์์ผ๊น?โ ์ ๋ํ ์ ์๊ฐ ๋๋ ์ด์ผ๊ธฐ์ด๋ค. ์ฌ์ค ์์ง ์ดํด๊ฐ ์ ๊ฐ์ง ์๋๋ค..
์ ๋๋ก ์๊ฐํ ์ ์๋ค.
์ค์ ๋ก,
<aside> ๐ก
1. ์ปฌ๋ ์ (List, Set ๋ฑ)
2. ๋ฐฐ์ด
3. Queue (์ปฌ๋์ ๊ธฐ๋ฐ์ด๋๊น)
4.Iterable ์ธํฐํ์ด์ค ๊ตฌํ์ฒด ( ๋์ด์ด ๊ฐ๋ฅํ๋ค ? ํ๋ฉด ๋ ๊ฐ๋ฅ์ฑ์ด ๋์์)
</aside>
๊ฐ์ ๊ฒฝ์ฐ streamํ ํด์ ํธ๋ฆฌํ ์์ ๋ค์ ์ฒ๋ฆฌํ ์ ์๋ค.
์๋ฅผ๋ค์ด, ๋ค์๊ณผ ๊ฐ์ ๋ฆฌ์คํธ๋ฅผ ๊ฐ์ง๊ณ ์๋ค๊ณ ์๊ฐํด๋ณด์.
List<String> fruits = new ArrayList<>(Arrays.asList("banana", "apple", "grape", "orange"));
๋ง์ฝ ์ด๋ค
List<String> fruits = new ArrayList<>(Arrays.asList("banana", "apple", "grape", "orange"));
List<String> updatedFruits = new ArrayList<>();
for (String fruit : fruits) {
// ๊ฐ ๋ฌธ์์ด์์ 'a'๋ฅผ ์ ์ธํ ๋ฌธ์์ด์ ์ ๋ฆฌ์คํธ์ ์ถ๊ฐ
String updatedFruit = fruit.replace("a", "");
updatedFruits.add(updatedFruit);
}
// ๊ฒฐ๊ณผ ์ถ๋ ฅ
System.out.println(updatedFruits);