java 8 forEach Loop Example using List and Map
forEach - forEach is available from java 8 and it is present in Iterable interface ( Interface Iterable<T> in java.lang package) and Stream Interface ( Interface Stream<T> in java.util.stream package). By using forEach loop we are able to iterate over the collection. Method Details - void forEach(Consumer<? super T> action) * Performs an action for each element of this stream. * This is a terminal operation. (I) forEach And List - * Before java 8 normal way to loop a List- List<String> list = new ArrayList<String>(); list.add("India"); list.add("USA"); list.add("UK"); list.add("China"); for(String s : list) ...