?????????Щ?????????????????????? :
????· boolean containsAll(Collection<?> c)
????????????????? c ????????
????· boolean addAll(Collection<? extends E> c)
?????????? c ?????е????????????У?????????и???? true
????· boolean removeAll(Collection<?> c)
??????????????к? c ????????μ?????????????и???? true
????· boolean retainAll(Collection<?> c)
??????????????? c ????????е?????????????и???? true
????· void clear()
??????????????
???????ж???????????????
????· Object[] toArray()
?????????????????????????????????
????· <T> T[] toArray(T[] a)
????????????????????????????????飬????????????????????????????????
?????? JDK 8 ???Collection ????????????????????????????????
????· Stream<E> stream()
????· Stream<E> parallelStream()
???????????????? Stream.
???????? Collection ?????????
????1??for-each??
????Collection<Person> persons = new ArrayList<Person>();
????for (Person person : persons) {
????System.out.println(person.name);
????}
????2????? Iterator ??????
????Collection<Person> persons = new ArrayList<Person>();
????Iterator iterator = persons.iterator();
????while (iterator.hasNext) {
????System.out.println(iterator.next);
????}
????3????? aggregate operations ??????
????Collection<Person> persons = new ArrayList<Person>();
????persons
????.stream()
????.forEach(new Consumer<Person>() {
????@Override
????public void accept(Person person) {
????System.out.println(person.name);
????}
????});
????Aggregate Operations ??????
?????? JDK 8 ????????t????????????????в???????????????? lambda ????????????????????????????????????????????????????????
????1.?????????????? ShapesCollection?????????????????
????myShapesCollection.stream()
????.filter(e -> e.getColor() == Color.RED)
????.forEach(e -> System.out.println(e.getName()));
????2.???????????????????parallelStream??????????????????ò??????????Ч???
????myShapesCollection.parallelStream()
????.filter(e -> e.getColor() == Color.RED)
????.forEach(e -> System.out.println(e.getName()));
????3.?????????к????????????????????????? Collection ?е???????? String ???????????? ????????
????String joined = elements.stream()
????.map(Object::toString)
????.collect(Collectors.joining("?? "));
???????????????????????
?????????????к??????????????????????????????Aggregate Operations ????????
????Iterator ??????
??????Java ?????????Iterator ?? Java ?????????ListIterator ??????? Collection ??????? Iterator ??????? List ??????? ListIterator??
??????? Collection ?? Iterator ????????Щ?????????????????????????
????public static void filter(Collection<?> c) {
????for (Iterator<?> it = c.iterator(); it.hasNext(); )
????if (!condition(it.next()))
????it.remove();
????}
??????? filter ??????????????????????? Collection ??????????? ??????????????? Java ?????????????????д?? “???????????????????” ?????~
???????
????Collection ??????????????????
??????????????????????е? 15 ???????????
??????????????м???????????? Collection??????????????????????????????????
???????????????????????????????????