Intermediate stream operations ကlazy ဖြစ်ပြီးterminal operation ကsingle-use pipeline ကိုစတင်ပါတယ်။
ပိုပြီးနားလည်ထားရမယ့် အချက်
Stream သည်data structure မဟုတ်ဘဲsource ပေါ်မှlazy, single-use processing pipeline ဖြစ်ပါတယ်။ Stateless, non-interfering operations သုံးပြီးside effects ကိုလျှော့ကာparallel stream ကိုmeasurement နဲ့correctness analysis မရှိဘဲမသုံးပါနှင့်။
လက်တွေ့မှာ ဘယ်လိုအသုံးချမလဲ
Collection ကိုfilter → map → collect pipeline ဖြင့်ပြောင်းပြီးsource မပြောင်းကြောင်း၊terminal operation မတိုင်မီlazy ဖြစ်ကြောင်းစမ်းပါ။
ဒီသင်ခန်းစာပြီးရင်
import java.util.List;
class Main {
public static void main(String[] args) {
List<String> names = List.of("ada", "grace", "linus");
List<String> result = names.stream()
.filter(name -> name.length() >= 5)
.map(String::toUpperCase)
.toList();
System.out.println(result);
}
}[GRACE, LINUS]ကိုယ်တိုင်စမ်းကြည့်ရန်
Collection ကိုfilter → map → collect pipeline ဖြင့်ပြောင်းပြီးsource မပြောင်းကြောင်း၊terminal operation မတိုင်မီlazy ဖြစ်ကြောင်းစမ်းပါ။
Common Mistake သတိပေးချက်
Consumed stream ကိုပြန်သုံးခြင်း သို့မဟုတ်`forEach` အတွင်းshared mutable state ပြောင်းပြီးparallel safety ကိုယူဆခြင်း။
Java Stream API — Oracle