Translate

New Live Courses

UpComing SoftWare Training Demos

🚀 *Playwright With AI Testing Demo In Telugu*
🗓️ *Date:* 28 Oct2026, 08:00 PM IST
📝 *Register Now!:*
https://www.vlrt.in/3r
👥 *Join WA Community:*
https://www.vlrt.in/3w
💡 *Course Content:*
https://www.vlrt.in/3c
▶️ *Demo Videos:*
https://www.vlrt.in/3v

🚀 *Gen AI Engineer (Production Focused)*
🗓️ *Date:* 29th Oct 2026, 06:00PM IST
📝 *Register Now!:*
https://www.vlrt.in/gr
👥 *Join WA Community:*
https://www.vlrt.in/gw
💡*Course Content:*
https://www.vlrt.in/ai
▶️ *Demo Videos:*
https://www.vlrt.in/gv

🚀 *Vulnerability Management Training Demo*
🗓️ *Date:* 28th Oct 2026, 10:00 AM IST
📝*Register Now!:*
https://www.vlrt.in/vr
👥 *Join Community:*
https://www.vlrt.in/cw
💡 *Course Content:*
https://www.vlrt.in/vc
▶️ *Demo Videos:*
https://www.vlrt.in/Vm

Thursday, 2 November 2023

Use of map function

 

Use of map function?

The map function is a powerful function in MuleSoft that can be used to transform data in a variety of ways. It is a higher-order function, which means that it takes a function as an argument and returns a new function as output.

https://youtu.be/Qg4cJF2x_o8

The map function is typically used to iterate over an array or a collection and apply a transformation to each element. The transformation can be anything from converting the element to a different type to performing a complex calculation on the element.

For example, the following code snippet shows how to use the map function to convert all of the elements in an array to uppercase:

 

import org.mule.runtime.api.util.ObjectUtils;

public class MapExample {

    public static void main(String[] args) {

        // Create an array of strings.
        String[] strings = new String[] { "one", "two", "three" };

        // Convert all of the elements in the array to uppercase.
        String[] upperCaseStrings = ObjectUtils.map(strings, (value) -> value.toUpperCase());

        // Print the upperCaseStrings array.
        System.out.println(upperCaseStrings);
    }
}


Output:

 

[ONE, TWO, THREE]


The map function can also be used to filter data. For example, the following code snippet shows how to use the map function to filter out all of the even numbers from an array:

 

import org.mule.runtime.api.util.ObjectUtils;

public class MapExample {

    public static void main(String[] args) {

        // Create an array of numbers.
        Integer[] numbers = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

        // Filter out all of the even numbers from the array.
        Integer[] oddNumbers = ObjectUtils.map(numbers, (value) -> value % 2 != 0);

        // Print the oddNumbers array.
        System.out.println(oddNumbers);
    }
}


Output:

 

[1, 3, 5, 7, 9]


The map function is a versatile and powerful function that can be used to transform data in a variety of ways. It is a valuable tool for Mule developers.

 

No comments:

Post a Comment

Note: only a member of this blog may post a comment.