I probably wouldn't declare the Streams in the first place.I said Streams because there are two of them: one in line 4 and one in line 5.
Several minor errors left unchanged, but they will prevent the code from compiling.
The limit() method takes a long as its parameter.
My tutor worked on this with me. I don't completely understand it, but the result and your comments match with what we came up with. We didn't think of making Limit 4L. I added an item to the Head First Eretta sheet. I'm not sure if the book has a mistake. It is confusing to me as a reader so I mentioned it. Let's see if they change it in the next edition.
If you copied your line 2 correctly, then it is incorrect and will fail to compile. My line 4 has, on the other hand, the correct types and will run correctly when you correct the minorr spellling misstakes.
Let's go through my version of your code. Lines 1‑2 create a List<String>. List#of() has overloadings and in this case it creates a 6‑element unmodifiable List. All the arguments should be of the same type (otherwise you would probably get a List<Object>), and in this case they are all Strings, so you get a List<String>. That should be pronounced, “List of Strings.” So far, so good.
See the Collection#stream() method. Line 4 does nothing until the terminal operation (line 6) runs. That is called lazy execution. If line 6 runs (and it does), then line 4 creates a Stream<String> which manipulates all the elements of the List in turn.
Look at Stream#limit(). That takes a long and produces a new Stream of the same type, but in this case it only has four elements. Since you are using one sequential Stream, that is done very simply by taking the first four elements. The link tells you that things can become more complicated if you use parallel Streams. Yes, you are using 4L if you pass an int because the limit() method will convert the 4 to a long. That's 4L.
Line 6 is a terminal operation because it doesn't create another Stream. If you look up collect(), you will find it takes a Collector. You can write your own Collector in three or four parts, but if you look in the Collectors class, you will find a method returning one ready‑made: here. So you call that and the Collector returned produces a List. It doesn't specify what sort of List however.
The remainder of the code should be obvious.
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
a bit of art, as a gift, the permaculture playing cards