package com.javatechie; import java.util.List; import java.util.stream.Collectors; public class MapVsFlatMap { public static void main(String[] args) { List customers = EkartDataBase.getAll(); //List convert List -> Data Transformation //mapping : customer -> customer.getEmail() //customer -> customer.getEmail() one to one mapping List emails = customers.stream() .map(customer -> customer.getEmail()) .collect(Collectors.toList()); System.out.println(emails); //customer -> customer.getPhoneNumbers() ->> one to many mapping //customer -> customer.getPhoneNumbers() ->> one to many mapping List> phoneNumbers = customers. stream().map(customer -> customer.getPhoneNumbers()) .collect(Collectors.toList()); System.out.println(phoneNumbers); //List convert List -> Data Transformation //mapping : customer -> phone Numbers //customer -> customer.getPhoneNumbers() ->> one to many mapping List phones = customers.stream() .flatMap(customer -> customer.getPhoneNumbers().stream()) .collect(Collectors.toList()); System.out.println(phones); } }