collections - addAll() implementation -- Java -
addall() of abstractcollection implemented follows:
public boolean addall(collection<? extends e> c) { boolean modified = false; (e e : c) if (add(e)) modified = true; return modified; } so, if c in parameter collection of, 3 elements, may case first 2 of these elements added, 3rd isn't added reason can't think of right now.
in case, addall() operation-- addition of of these 3 elements underlying collection isn't carried , addall() returning false should. however, first 2 elements there-- , developer expect shouldn't be(?)
hashset using addall() in constructor-with-a-single-param of type collection.
so, developer end hashset instance contains part of collection while he`s looking entire collection. , happens without warnings.
the methods involved-- put() of hashmap , add() of hashset seem straightforward enough-- doesn`t seem can go wrong during these operations-- still.
am missing here?
so, developer end
hashsetinstance contains part of collection while he`s looking entire collection. , happens without warnings.
not true. fact set.add returns false means there. exceptions bounded collections have size limits, @ point developer should know it's bounded collection anyway , won't contain elements. collections in collections api, calling addall guarantees containsall return true if call same collection. i.e. print true:
set<t> set1 = new hashset<>(); set<t> set2 = new hashset<>(); // add stuff sets set1.addall(set2); system.out.println(set1.containsall(set2));
Comments
Post a Comment