June 2018
Beginner
722 pages
18h 47m
English
This Set functionality is not different from List as described previously, because every collection that implements the Collection interface also implements the Iterable interface (because Collection extends Iterable) Set can be iterated using a traditional enhanced for statement or its own method forEach():
Set set = new HashSet();set.add(null);set.add(1);set.add("ss");set.add(new A());set.add(new B());for(Object o: set){ System.out.println(o);}set.forEach(System.out::println);
In Chapter 17, Lambda Expressions and Functional Programming, we will explain how the function can be passed as a parameter of the method forEach(). The result of both iteration styles is the same:
The other related methods that come from the interface ...
Read now
Unlock full access