Java Program to convert integer to String with Map

Java 8Object Oriented ProgrammingProgramming

Let’s say we have an Integer array with the following elements:

20, 50, 100, 200, 250, 300, 500, 550, 600, 700

Convert it to List:

Arrays.asList(20, 50, 100, 200, 250, 300, 500, 550, 600, 700)

Use Map to get the values greater than 400 and convert to String:

filter(val -> val > 400) .map(val -> "Value greater than 400 = " + String.valueOf(val))

The following is an example to convert integer to String with Map:

Example

import java.util.Arrays;
public class Demo {
   public static void main(String[] args) {
      Arrays.asList(20, 50, 100, 200, 250, 300, 500, 550, 600, 700)
         .stream()
         .filter(val -> val > 400)
         .map(val -> "Value greater than 400 = " + String.valueOf(val))
         .forEach(val -> System.out.println(val));
   }
}

Output

Value greater than 400 = 500
Value greater than 400 = 550
Value greater than 400 = 600
Value greater than 400 = 700
raja
Published on 02-May-2019 07:57:55
Advertisements