java - Why an object is removed after using removeAll method -


i have executed program. after removing object list reflects list.

public class testing {      public static void main(string args[]) {         arraylist a1 = new arraylist<>();         a1.add("a");         a1.add("e");         a1.add("f");         arraylist a2 = new arraylist<>();         a2.add("a");         a2.add("x");         a2.add("y");          a1.removeall(a2);         iterator<string> = a1.iterator();         while (it.hasnext()) {             system.out.println(it.next());         }     } 

and output i'm getting is: e,f

why 'a' removed ?

because called a1.removeall(a2) perhaps?

http://docs.oracle.com/javase/7/docs/api/java/util/list.html#removeall%28java.util.collection%29

removes list of elements contained in specified collection (optional operation).

so, in other words, every element that's in a2 , in a1 removed a1.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -