[Java] Stream API / map

A method that transforms all the elements in an object

public class Fruit {
	
	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()).collect(Collectors.toList());
		ret.forEach(System.out::println);
	}
}

//The output result has uppercase elements

(.Collect (Collectors.toList ()); is attached to return as List)

** If you don't use a lambda expression, it looks like this: ** **

		List<String> ret = list.stream().map(new Function<String,String>(){
			@Override
			public String apply(String s) {
				System.out.println(s);
				return s.toUpperCase();
			}
		}).collect(Collectors.toList());

map () has a Function as an argument

Interface Function <T, R> T… Argument type R ... Return type

Why can apply be used suddenly? Since there are only apply methods in the interface Function (default is ignored)

Recommended Posts

[Java] Stream API / map
Java Stream API
Stream API map method
Java8 Stream API practice
Java Stream API cheat sheet
Java Stream API in 5 minutes
JAVA (Map)
[Java] Stream API --Stream termination processing
[Java] Stream API --Stream intermediate processing
[Java] Introduction to Stream API
[Java] Stream API intermediate operation
[Java] Stream (filter, map, forEach, reduce)
[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
Java8 list conversion with Stream map
Stream API memo
[JAVA] Stream type
Try Java 8 Stream
[Java] Map comparison
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)
Docker-Client Java API Troubleshooting
Enum reverse map Java
Zabbix API in Java
Java8 Stream reduction operation
Java bidirectional map library
[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] How to use Map
[Java] How to use Map
[Java11] Stream Summary -Advantages of Stream-
Java8 stream, lambda expression summary
How to use Java Map
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
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