Posts

Showing posts from November, 2024

Java8 Iteration Ideas

# Java8 Internal and External Iteration Concepts - [Using External Iteration](#user-content-using-external-iteration) - [Internal Iteration Using Streams](#user-content-internal-iteration-using-streams) - [Lazy and Eager filters](#user-content-lazy-and-eager-filters) In this tutorial, we will explore different kinds of iterations using code examples ## Using External Iteration Lets say we want to count the liverpool based artists, we could do: ``` int count=0; for(Artist artist : allArtists){ if(artist.isFrom("liverpool")){ count++; } } ``` Now we are internally using the iterator to iterate over the artists. So, technically under the hood, its doing the following: ``` int count=0; Iterator<Artist> iterator = allArtists.iterator(); while(iterator.hasNext()){ Artist artist = iterator.next(); if(artist.isFrom("liverpool")){ count++; } } ``` - This is "external" iteration - Its inherently "serial" i...