đĨ Iterable vs MutableIterable āϏāĻšāĻāĻাāĻŦে āĻŦোāĻা!
đĨ Iterable vs MutableIterable āϏāĻšāĻāĻাāĻŦে āĻŦোāĻা!
āϤুāĻŽি āĻি āĻāĻāύো āĻāĻāĻা āĻŦāĻ āĻĒā§াāϰ āϏāĻŽā§ āĻļুāϧু āĻĒā§āϤে āĻĒাāϰো āĻিāύ্āϤু āϞিāĻāϤে āĻĒাāϰো āύা? đ
āĻāĻŦাāϰ āĻিāĻু āĻĄাā§েāϰি āĻĨাāĻে āϝেāĻাāύে āϤুāĻŽি āĻĒā§āϤেāĻ āĻĒাāϰো, āϞিāĻāϤেāĻ āĻĒাāϰো! đ
đ Iterable āĻšāϞো āĻļুāϧু āĻĒā§াāϰ āĻāύ্āϝ (Read-Only)।
đ MutableIterable āĻšāϞো āĻĒā§াāϰ āϏাāĻĨে āϏাāĻĨে āĻĒāϰিāĻŦāϰ্āϤāύāĻ (Add/Remove) āĻāϰা āϝাā§!
đ¯ 1. Iterable (āĻļুāϧু āĻĒā§া āϝাā§, āĻĒāϰিāĻŦāϰ্āϤāύ āĻāϰা āϝাā§ āύা!)
val numbers: Iterable<Int> = listOf(1, 2, 3, 4, 5)
for (num in numbers) {
println(num) // āĻļুāϧু āĻĒā§া āϝাāĻŦে
}
// numbers.add(6) ❌ (Error: add() āύেāĻ, āĻাāϰāĻŖ āĻāĻি Immutable)
✅ āĻāĻাāύে numbers āĻļুāϧুāĻŽাāϤ্āϰ āĻĒā§াāϰ āĻāύ্āϝ āĻŦ্āϝāĻŦāĻšাāϰ āĻāϰা āϝাāĻŦে, āĻিāύ্āϤু āĻোāύো āĻিāĻু āϝোāĻ āĻŦা āĻŽুāĻāϤে āĻĒাāϰāĻŦে āύা।
đ 2. MutableIterable (āĻĒā§া + āĻĒāϰিāĻŦāϰ্āϤāύ āĻāϰা āϝাā§!)
val numbers: MutableIterable<Int> = mutableListOf(1, 2, 3, 4, 5)
val iterator = numbers.iterator()
while (iterator.hasNext()) {
if (iterator.next() == 3) {
iterator.remove() // MutableIterable āĻĻিā§ে remove āĻāϰা āϝাāĻ্āĻে!
}
}
println(numbers) // Output: [1, 2, 4, 5]
✅ āĻāĻাāύে MutableIterable āĻŦ্āϝāĻŦāĻšাāϰ āĻāϰাā§ remove() āĻĢাংāĻļāύ āĻĻিā§ে ā§Š-āĻে āĻŽুāĻে āĻĢেāϞা āĻেāĻে!
⚡ Iterable vs MutableIterable āĻĒাāϰ্āĻĨāĻ্āϝ āϏংāĻ্āώেāĻĒে!
| Feature | Iterable (āĻļুāϧু āĻĒā§া) | MutableIterable (āĻĒā§া + āĻĒāϰিāĻŦāϰ্āϤāύ) |
|---|---|---|
| Read (āĻĒā§া) | ✅ āĻš্āϝাঁ | ✅ āĻš্āϝাঁ |
| Modify (āĻĒāϰিāĻŦāϰ্āϤāύ) | ❌ āύা | ✅ āĻš্āϝাঁ (remove āĻāϰা āϝাā§) |
| Usage Example | listOf(), setOf() |
mutableListOf(), mutableSetOf() |
| Allowed Methods | forEach, map, filter |
iterator().remove() |
đ āĻļেāώ āĻāĻĨা!
đ Iterable = āĻļুāϧু āĻĒā§āϤে āĻĒাāϰো, āĻিāύ্āϤু āĻŦāĻĻāϞাāϤে āĻĒাāϰো āύা!
đ MutableIterable = āĻĒā§āϤে āĻĒাāϰো + āĻŦāĻĻāϞাāϤেāĻ āĻĒাāϰো!
āĻāĻāύ āĻĒাāϰ্āĻĨāĻ্āϝ āĻ্āϞিā§াāϰ? đđđĨ
Comments
Post a Comment