IntStream map(IntUnaryOperator mapper) in Java Last Updated : 06 Dec, 2018 Comments Improve Suggest changes Like Article Like Report IntStream map(IntUnaryOperator mapper) returns a stream consisting of the results of applying the given function to the elements of this stream. This is an intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output. Syntax : IntStream map(IntUnaryOperator mapper) Parameters : IntStream : A sequence of primitive int-valued elements. IntUnaryOperator : An operation on a single int-valued operand that produces an int-valued result. mapper : A stateless function which is applied to each element and the function returns the new stream. Return Value : IntStream map(IntUnaryOperator mapper) returns a stream by applying the given function. Example 1 : Using IntStream map() to get the negative of square of elements of IntStream. Java // Java code for IntStream map // (IntUnaryOperator mapper) to get a // stream by applying the given function. import java.util.*; import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // Creating an IntStream IntStream stream1 = IntStream.of(4, 5, 6, 7); // Using IntStream map() IntStream stream2 = stream1.map(num -> (-num * num)); // Displaying the resulting IntStream stream2.forEach(System.out::println); } } Output: -16 -25 -36 -49 Example 2 :Using IntStream map() to get the half of elements of IntStream in given range. Java // Java code for IntStream map // (IntUnaryOperator mapper) to get a // stream by applying the given function. import java.util.*; import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // Creating an IntStream in range [2, 7) IntStream stream1 = IntStream.range(2, 7); // Using IntStream map() IntStream stream2 = stream1.map(num -> (num / 2)); // Displaying the resulting IntStream stream2.forEach(System.out::println); } } Output: 1 1 2 2 3 Create Quiz Comment S Sahil_Bansall Follow 0 Improve S Sahil_Bansall Follow 0 Improve Article Tags : Misc Java Java - util package Java-Functions java-stream java-intstream +2 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like