java - Using equals() and == in an enhanced for loop -
java - Using equals() and == in an enhanced for loop -
lets there array contains series of objects,
object[] list;
and method designed iterate through array, example
public boolean contains(object e) { for(object e_:list) if(e_.equals(e)) homecoming true; homecoming false; }
what i'm confused how loop iterates array. when iterating, assign e_ same memory location list[index] or e_ new object cloned list[index], because want utilize == instead of equals() can phone call object , not risk beingness equal() another. understand override equals() , create final prevent inheritance beingness issue, understand how iteration works. preferably reply in layman's terms , not send me website, because have been on oracle , other forums, , explanations read little on head.
there cloning in java. assignment (=) operator in java not clone objects. a=b sets reference same value b. (a==b) true. when set objects list/array objects not cloned. when iterate through array it's same reference values set in there.
java arrays foreach
Comments
Post a Comment