Thursday, May 5, 2022

Question 11: Given a list of integers, find out all the numbers starting with 1 using Stream functions?


import java.util.*; import java.util.stream.*; public class JavaHungry { public static void main(String args[]) { List<Integer> myList = Arrays.asList(10,15,8,49,25,98,32); myList.stream() .map(s -> s + "") // Convert integer to String .filter(s -> s.startsWith("1")) .forEach(System.out::println); } }

Output:
10, 15

Don't miss the next article! 
Be the first to be notified when a new article or Kubernetes experiment is published.                            

   Share This

You may also like

Kubernetes Microservices
Python AI/ML
Spring Framework Spring Boot
Core Java Java Coding Question
Maven AWS