Write a Java program using Java 8 to find smallest numbers from the array list.

Problem:- Write a Java program using Java 8 to find the three smallest numbers from the array list.

Solution:- 



package com.codeforsolution.java8;

import java.util.stream.IntStream;

public class FindThreeSmallestDistinctNumbers {

	public static void main(String[] args) {
		int[] numbers = {5, 4, 10, 12, 0 ,5, 6, 9, 0, 3, 7};
		IntStream.of(numbers).distinct().sorted().limit(3).forEach(System.out::println);

	}

}
Output:-

0

3

4

Post a Comment (0)
Previous Post Next Post