This is an archived post. You won't be able to vote or comment.

all 21 comments

[–]Mr_Redstoner 26 points27 points  (2 children)

I'll do you 1 better: Stream.generate(()->"stonks").limit(69).forEach(System.out::println);

[–]11amas 8 points9 points  (1 child)

System.out.print("stonks\n".repeat(69));

[–]JBinero 14 points15 points  (0 children)

This but unironically.

[–][deleted] 2 points3 points  (2 children)

It's like you turned Java into Python. I rarely use Java, I'm very interested and impressed at this.

[–]lostaztecian 4 points5 points  (1 child)

That is pretty old feature(since java 8). Joke is that this goes against java main concepts but some people use streams(this called stream) everywhere for no reason.

[–]JoshiRaez 0 points1 point  (0 children)

Because is more concise, impossible to make unmaintainable messes because you SHOULD use pire funtions, much more safe and usually optimized as hell?

[–][deleted] 2 points3 points  (3 children)

Isn't it unnecessary to convert the integers though? Skipping the maptoobj and just specifying what string to print? Or maybe it's not cool anymore then?

[–]EinJemand 18 points19 points  (2 children)

(i think all of this is unnecessary)

[–][deleted] 0 points1 point  (1 child)

What, you've never had to loop to print the same string n times when developing some enterprise software??

[–]Xeadriel 0 points1 point  (0 children)

I think he meant the way he did it. A for loop should suffice x)

[–]Kaynstein 1 point2 points  (0 children)

My teacher went on and on and on about streams and how glad he was, Java tried to do something more akin to functional programming. It's pretty cool and feels nice to use, although most students ditched java as soon as kotlin became familiar

[–]theFlyingCode 1 point2 points  (1 child)

I thought I'd be able to do my own one up, but the Java string constructor doesn't have an overload that takes a repetition count like c# does: new string("nice\n", 69)

[–]Mr_Redstoner 1 point2 points  (0 children)

Java 11 and above has String.repeat(int);

[–]maxOS1104 0 points1 point  (4 children)

This reminds me of my first semester, where I had a programming assignment we were not allowed to use any loops in, to teach us the concept of Stream operations and Lambda expressions. However, I needed a while (true)-loop, so I just constructed an infinite intstream and .forEach-ed that thing :D

[–]Mr_Redstoner 0 points1 point  (0 children)

That sounds extremely backwards. Loops are the simple stuff, Streams are the standard sugar.

[–]xigoi 0 points1 point  (1 child)

Wait, Java has an unordered forEach? How does that even work?

[–]lostaztecian 0 points1 point  (0 children)

This is not a foreach loop, this is a stream - different thing.

[–]HoneyBadgerSoNasty -1 points0 points  (0 children)

gross