Java8 Stream API practice

It's been a long time since I left the site, so I'm practicing Java 8.

It is possible to write Java8 like Java6, and I know that there are many sites where it will happen if you match it to the lowest level of the programmer, but now the idea that useful things should be incorporated and improved. Does not change.

I've created a fucking code, so I'm ashamed to publish it.


//Imagine if you want to create a lot of test data.
//bad example
List<MyObject> objs = Stream.of(1, 2, 3, 4, 5).map(i -> {
    MyObject myObj = new MyObject();
    /*Do various things*/
    return myObj;

//Good example
// IntStream#range()If so, 5 will not come out, so be careful
List<MyObject> objs = IntStream.rangeClosed(1, 5).mapToObj(i -> {
    MyObject myObj = new MyObject();
    /*Do various things*/
    return myObj;

My boom is to make the variable names of the collection plural (-s, -es). If you name it like xxxList, it feels like Hungarian and it feels uncomfortable, and there is a possibility that the type will not be List, so I've been confused for about 5 years.

I wondered if I couldn't write it like Perl, so I spent about 30 minutes trying and error. I wrote the argument of Stream # of () as 1.5, but it doesn't work. It's Java, not Perl.


#Note: Perl-like writing
my @array = (1 .. 5);

By the way, is Perl still active?

At the same time as the Struts stop campaign, a lot of Perl application abolition projects came and it was quite awkward. I want to replace it, but there is no design document, and there are few engineers who can reverse engineer.

I've been letting Python do all the little things these days. I'm good at writing Perl, but it's inconvenient that I can't use CPAN in an environment disconnected from the Internet ...

Recommended Posts

Java8 Stream API practice
Java Stream API
[Java] Stream API / map
Java Stream API cheat sheet
[Java] Stream API --Stream termination processing
[Java] Stream API --Stream intermediate processing
[Java] Introduction to Stream API
[Java] Stream API intermediate operation
[java8] To understand the Stream API
[Introduction to Java] About Stream API
I tried using Java8 Stream API
Java 8 ~ Stream API ~ to start now
[JAVA] Stream type
Try Java 8 Stream
java practice part 1
Studying Java 8 (Stream)
Java Stream termination
[Java] Stream processing
Stream API basics
Java 9 Optional :: stream
Data processing using stream API from Java 8
Try using the Stream API in Java
Nowadays Java lambda expressions and Stream API
Try various Java Stream API methods (now)
[Java] Stream Collectors notes
Pack API response (java)
[Java] Stream API-Stream generation
Stream API (Collectors class)
Stream API map method
Docker-Client Java API Troubleshooting
Rock-paper-scissors game java practice
Scraping practice using Java ②
Zabbix API in Java
Java8 Stream reduction operation
Scraping practice using Java ①
[Java] How to operate List using Stream API
Java8 Stream Rough Summary
[In-house study session] Java basics-Lambda expression and Stream API- (2017/07/13)
[For beginners] How to operate Stream API after Java 8
Use Java lambda expressions outside of the Stream API
[Java] Practice of exception handling [Exception]
[Java11] Stream Summary -Advantages of Stream-
Java Stream cannot be reused.
Use Redis Stream in Java
[Java11] Stream Usage Summary -Basics-
Java Basic Learning Content 8 (Java API)
Java application for beginners: stream
Recent Java API specification generation
[Must-see for apprentice java engineer] How to use Stream API
Handle exceptions coolly with Java 8 lambda expressions and Stream API
Convert 2D array to csv format with Java 8 Stream API
[Java 8] Duplicate deletion (& duplicate check) with Stream
Export issues using JIRA's Java API
About Lambda, Stream, LocalDate of Java8
Java HTTP Client API timeout setting
[Java] Element existence check with Stream
Create an easy-to-extend Stream API alternative
Hit Zaim's API (OAuth 1.0) in Java
Parsing the COTOHA API in Java
Basic processing flow of java Stream