0

I'm realy counting the seconds, cuz of getting an answer for this Q

I'm really wondered about the way the Enhanced - for- loop in #Java gets used.. We declare or define or initialize or whatever u call, the Enhanced for loop like this[for ( int w : myArr) ] N here's my question : can anybody realy Elaborate those kinda initializations n how we can assign a value to a object's attribute without even declaring that attribute in a specific class !!? Appreciating all #Repliers in advance 😘

13th Dec 2017, 2:01 PM
UbuUunTu✔
UbuUunTu✔ - avatar
3 RĂ©ponses
+ 6
The "foreach" version: by this way we can declare it for (String s : list) { if (s.equals("a")) list.remove(s); } internally is equivalent to for(Iterator<String> i = list.iterator(); i.hasNext(); ) { String s = i.next(); if (s.equals("a")) list.remove(s); }
13th Dec 2017, 2:18 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
Tnx u guys.. I got it.. I was just misunderstanding n misinterpreting the entire process with the object instantiation n class concepts .. By the Enhanced for-loop we r just declaring a simple variable n assigning it, a value.. Sometimes things r so clear n plain which u never ever imagined it could be 😇
13th Dec 2017, 3:40 PM
UbuUunTu✔
UbuUunTu✔ - avatar
0
While I understand your statement about the for statement, as you gave the code. Your real question doesn't make sense to me. for (int w : myArr) { } is the the same as for (int i = 0; i < myArr.length; i++) { int w = myArr[i]; } so if your talking about w's initialization, hopefully it now makes sense. Your second part about assigning to an undeclared attribute isn't legal ever so odds are you're confused about the attribute status or your using terms that are confusing me. Please try to show code for both parts or better description so I can help.
13th Dec 2017, 2:36 PM
John Wells
John Wells - avatar