[Java] Stream API intermediate operation

filter (extraction)

-Filter the data that matches the conditions. -For the argument, write a conditional expression in which boolean is the return value.

Object name.stream (). Filter (dummy argument-> conditional expression);

public static void main(String[] args) {
		
	List<String> list = new ArrayList<>();
	list.add("apple");
	list.add("orange");
	list.add("banana");
		
	list.stream()
		.filter(i -> i != "apple");//from list"Except for apple is extracted"
}

sorted

-Primitive types that do not implement Comparatable can only be sorted in ascending order -For types that implement Comparatable (String, Integer, etc.), you can specify ascending and descending order with Comparator. In the case of ascending order, Comparator.naturalOrder () can be omitted.

Object name.stream (). Sorted (ascending or descending);

public static void main(String[] args) {
		
	List<String> list = new ArrayList<>();
	list.add("lemon");
	list.add("orange");
	list.add("apple");
		
	list.stream().sorted(Comparator.naturalOrder());//ascending order
	list.stream().sorted(Comparator.reverseOrder());//descending order
}

map() ยท Convert elements in an object

Object name.stream (). Map (dummy argument-> conversion process);

public static void main(String[] args) {
		
	List<String> list = new ArrayList<>();
	list.add("apple");
	list.add("orange");
	list.add("banana");
		
	List<String> ret = list.stream().map(s -> s.toUpperCase());//Convert from lowercase to uppercase
}

Recommended Posts

[Java] Stream API intermediate operation
Java Stream API
[Java] Stream API / map
Java8 Stream reduction operation
Java Stream API cheat sheet
[Java] Introduction to Stream API
[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
It's not too late yet? Java Stream API all method usage example (intermediate operation)
Data processing using stream API from Java 8
[JAVA] Stream type
Try using the Stream API in Java
Try Java 8 Stream
Nowadays Java lambda expressions and Stream API
Try various Java Stream API methods (now)
Studying Java 8 (Stream)
Java Exercise "Intermediate"
Detailed behavior of Stream API Stateful intermediate operation and short-circuit termination operation
Stream intermediate processing
Java Stream termination
[Java] Stream processing
Stream API basics
Java 9 Optional :: stream
[Java] How to operate List using Stream API
[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
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
[Java11] Stream Summary -Advantages of Stream-
Basics of character operation (java)
[Must-see for apprentice java engineer] How to use Stream API
Handle exceptions coolly with Java 8 lambda expressions and Stream API
Elasticsearch Operation via REST API using Apache HttpClient in Java
Java Stream cannot be reused.
Use Redis Stream in Java
Convert 2D array to csv format with Java 8 Stream API
Java application for beginners: stream
Recent Java API specification generation
Leverage Either for individual exception handling in the Java Stream API
[Java 8] Duplicate deletion (& duplicate check) with Stream
Operation to connect multiple Streams @Java
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
Call TensorFlow Java API from Scala
Java array / list / stream mutual conversion list
Java8 list conversion with Stream map
Do you use Stream in Java?