Generally there's no difference. NewClass::new produces less bytecode as in lambda version an auto-generated private method is created by java compiler from the lambda body while NewClass:new directly links to the constructor method handle. So using method references you may have slightly less class file size. No significant performance difference is expected though.

Another difference is method resolution procedure. It's not applicable in your particular example, but may be applicable in other code. For example, you have two constructors:

public NewClass(String a) {...}
public NewClass(String a, String b) {...}

And you have some method which accepts functional interface:

public myMethod(Function<String, NewClass> fn) {...}

Then you can call it both with lambda or functional interface:

myMethod(str -> new NewClass(str));
myMethod(NewClass::new);

But suppose that later you add a new method with the same name like this:

public myMethod(BiFunction<String, String, NewClass> fn) {...}

Then method reference call will become ambiguous and will result in compilation error as NewClass::new now matches to both constructors, while lambda is still unambiguous.

Answer from Tagir Valeev on Stack Overflow
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › java stream map()
Java Stream map() with Examples - HowToDoInJava
August 26, 2023 - Java 8 Stream.map() converts Stream to Stream. For each object of type X, a new object of type Y is created and put in the new Stream.
🌐
Java2s
java2s.com › Tutorials › Java › Stream_How_to › Stream_Map › Map_object_to_create_new_object.htm
Java Stream How to - Map object to create new object
Back to Stream Map ↑ · We would like to know how to map object to create new object. import java.util.Arrays; import java.util.List; import java.util.stream.Stream; //w w w .jav a 2s.
🌐
Mkyong
mkyong.com › home › java8 › java 8 streams map() examples
Java 8 Streams map() examples | mkyong.com
April 3, 2017 - package com.mkyong.java8; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class TestJava8 { public static void main(String[] args) { List<Staff> staff = Arrays.asList( new Staff("mkyong", 30, new BigDecimal(10000)), new Staff("jack", 27, new BigDecimal(20000)), new Staff("lawrence", 33, new BigDecimal(30000)) ); //Before Java 8 List<String> result = new ArrayList<>(); for (Staff x : staff) { result.add(x.getName()); } System.out.println(result); //[mkyong, jack, lawrence] //Java 8 List<String> collect = staff.stream().map(x -> x.getName()).collect(Collectors.toList()); System.out.println(collect); //[mkyong, jack, lawrence] } } 3.1 This example shows you how to convert a list of staff objects into a list of StaffPublic objects.
🌐
Baeldung
baeldung.com › home › java › java collections › java map › working with maps using streams
Working With Maps Using Streams | Baeldung
November 10, 2025 - We only want to consider the entries with “Effective Java” as the title, so the first intermediate operation will be a filter. We’re not interested in the whole Map entry, but in the key of each entry. So the next chained intermediate operation does just that: it is a map operation that will generate a new stream as output, which will contain only the keys for the entries that matched the title we were looking for.
🌐
TutorialsPoint
tutorialspoint.com › convert-an-object-to-another-type-using-map-method-with-lambda-in-java
Convert an object to another type using map() method with Lambda in Java?
The map() method is an intermediate operation in a stream object, so we need a terminal method to complete the stream. <R>Stream <R> map(Function<? super T,? extends R> mapper) import java.util.*; import java.util.stream.*; public class EmployeeInformationTest { public static void main(String args[]) { List<Employee> employees = Arrays.asList( new Employee("Jai"), new Employee("Adithya"), new Employee("Raja")); List<String> names = employees.stream() .map(s -> s.getEmployeeName()) // Lambda Expression .collect(Collectors.toList()); System.out.println(names); } } // Employee class class Employe
Top answer
1 of 2
4

You did not say what ´mapToOther` should or should not do.

So assume:

  • mapToOther has the signature Other mapToOther(MyObject obj), and transforms obj of type MyObject to a new object of type Other

  • it does not keep a reference to obj somewhere else (maybe in some cache)

  • it does not put a reference to obj into the newly created ´Other` object

  • the implementation of the Stream classes is quite sane and takes cares not to create memory leaks

then the source objects are "garbage collectable" right after the assignment. If one of the above assumptions is violated, then the MyObject instances will continue to "live".

To answer your comment:

as the stream goes through each source object, would each of them be garbage collectable right after it completes the map but before all completed the map

This ultimately depends on the underlying implementation of Stream.of and map. The Stream documentation discourages multiple consumptions of a stream, hence there is no mandatory reason for the elements to be kept in scope right after they were processed. On the other hand, Stream.of uses varargs, so all of the instances of MyObject are first created and then put into an array internally before .of is executed. The most straightforward implementation of of and map might simply keep the elements in that array internally. So I would usually expect the elements are not garbage collectable before the assignment is completed.

2 of 2
4

As far as garbage collection goes it does what this does:

Other other = mapToOther(new MyObject());

That is, if mapToOther() leaves other holding a hard reference to your MyObject instance they will live and die together. If not the MyObject instance is eligible for garbage collection when you hit the semicolon. These things have been called nameless temporary objects or anonymous objects. Not every object gets directly associated with an identifier like a variable. But they can live forever in an object graph. That's one of the reasons circular references are such a bad thing.

🌐
Stack Abuse
stackabuse.com › java-8-stream-map-examples
Java 8 - Stream.map() Examples
February 23, 2023 - This is why we can chain multiple intermediate operations without using semicolons. Intermediate operations include the following methods: map(op) - Returns a new stream in which the provided op function is applied to each of the elements in the original stream
🌐
Scaler
scaler.com › home › topics › java stream map()
Java Stream map() - Scaler Topics
June 22, 2024 - The Java Stream map() method is used to return a new stream of objects.
Find elsewhere
🌐
Java Development Journal
javadevjournal.com › home › java streams map() examples
Java Streams map() Examples | Java Development Journal
May 19, 2020 - If we want to store the filtered list in a different variable, we can remove the property userName because all these objects will be for a specific user. The name will be the same for all. In such scenarios, we can create one distinct class to hold only the required data and using map(), we can convert one type to another. I will continue with the above example. Create one new class Location to store only latitude and longitude :
🌐
Baeldung
baeldung.com › home › java › java list › create list of object from another type using java
Create List of Object From Another Type Using Java | Baeldung
March 7, 2025 - We can interpret the problem in this way: filtering the employees whose hobbies cover tennis and transforming these Employee objects into TennisPlayerCandidate objects. Stream’s filter() and map() methods can support us to finish the task easily. Next, let’s “translate” the idea into Java code: List<TennisPlayerCandidate> result = EMPLOYEES.stream() .filter(e -> e.getHobbies().contains("Tennis")) .map(e -> new TennisPlayerCandidate(e.getName(), e.getEmail())) .collect(Collectors.toList()); assertEquals(EXPECTED, result);
🌐
codippa
codippa.com › home › java 8 stream map() method
Java 8 stream map() to convert one object to another
January 11, 2025 - map() method in java 8 stream is used to convert an object of one type to an object of another type or to transform elements of a collection.
🌐
ConcretePage
concretepage.com › java › jdk-8 › java-8-stream-map-example
Java Stream map()
In this example we will convert a List of an object into another List of different object using Stream.map() as an intermediate operation. ListToAnotherList.java · package com.concretepage; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class ListToAnotherList { public static void main(String[] args) { Person p1 = new Person(1, "Mohan", "student"); Person p2 = new Person(2, "Sohan", "teacher"); Person p3 = new Person(3, "Dinesh", "student"); List&ltPerson&gt personList = Arrays.asList(p1, p2, p3); List&ltStudent&gt stdList = personList.stream().filt
🌐
Medium
medium.com › @AlexanderObregon › javas-stream-map-method-explained-df0d0d461d39
Java’s Stream.map() Method Explained | Medium
August 27, 2024 - The map() method is a key part of Java's Stream API. It allows you to apply a given function to each element of the stream, producing a new stream with the transformed elements.
🌐
ZetCode
zetcode.com › java › streammap
Java Stream map - map operations on Java streams
Each string is split into first and last names, which is then used to create a new User object. This approach allows us to transform raw data into structured objects for easier manipulation and processing within our application. The mapToInt method is a specialized version of the map method ...
🌐
Medium
medium.com › @gauravverma.career › mastering-the-map-operation-in-java-streams-d8c819ae9e4b
Mastering the map() Operation in Java Streams | by Gaurav Verma | Medium
December 7, 2025 - Non-Modifying (Immutability): map() does not modify the elements of the original data source or the elements within the original stream. Instead, it creates a new stream containing the transformed elements.
🌐
GeeksforGeeks
geeksforgeeks.org › java › stream-map-java-examples
Stream map() in Java with examples - GeeksforGeeks
January 4, 2025 - Stream is an interface and T is the type of stream elements. mapper is a stateless function which is applied to each element and the function returns the new stream. ... Stream map() function with operation of number * 3 on each element of stream. ...
🌐
Medium
rameshfadatare.medium.com › java-stream-map-method-with-real-world-examples-2f36739a13e2
Java Stream map() Method with Real-World Examples | by Ramesh Fadatare | Medium
March 2, 2025 - The Stream API in Java provides the map() method, which allows you to transform each element of a stream into another form. ... Transforms each element in a stream into a new form.