Skip to main content

Command Palette

Search for a command to run...

1. Stream API coding questions

https://www.youtube.com/watch?v=Q3T7GEvkGsU&list=PL63BDXJjNfTElajNCfg_2u_pbe1Xi7uTy&index=40

Updated
4 min read

2. Given a sentence, find the word that has the highest length

3. Remove duplicates from the string and return in the same order

4. Find the word that has the second-highest length

5. Find the 2nd highest length word in the given sentence

6. Given a sentence, find the occurrence of each word

7. Given a sentence, find the words with a specified number of vowels

8. Divide given integer list into lists of even and odd numbers

9. Given a word, find the occurrence of each character

0/P → { p=2, s=4, i=4, M=1 }

10. Arrange the numbers in Descending/Ascending Order

11. Given an array, find the sum of unique elements

12. Given a string, find the first non-repeated character

13. Given a string, find the first repeated character

import java.util.*;
import java.util.stream.*;

class Main {
    public static void main(String[] args) {
        String s = "Hello world";

        String res = Arrays.stream(s.split(""))
                           .filter(c -> s.indexOf(c) != s.lastIndexOf(c))
                           .findFirst()
                           .orElse(null);

        System.out.println(res);
    }
}

14. Given an array of integers, group the numbers by the range

15. Given a list of strings, create a list that contains only integers

16. Find the products of the first two elements in an array.

17. Group /Pair anagrams from a list of Strings.

0/p:

18. Write a stream program to multiply alternative numbers in an array.

19. Write a program to multiply 1st and last element, 2nd and 2nd last element etc.

O/P :

20. Write a stream program to move all zero’s to beginning of array.

O/P :

21. In a given array of integers, return true if it contains distinct values.

O/P

22. Given the string[] group the strings based on the middle character

23. Find the sum of all the elements in a list.

24. Sort a list of strings in alphabetical order.

25. Convert a list of integers to a list of their squares

26. Find and print the distinct odd numbers

27. Find the union of two lists of integers

28. Find the kth smallest element in a list of integers.

29. Remove all non-numeric characters from a list.

30. Convert a list of strings to uppercase.

31. Calculate the average of all the numbers.

32. Convert a list to a map

33. Multiply array elements

34. Find Longest String from an Array of Strings?

35.keep only numbers that start with 1 from an int[]

36. filtering numbers starting with 1 from a List

37. Find common elements between two arrays

38. count a particular character from a String

39. Given a list of strings, write a program to find and print the strings containing only digits using Java Stream API

40.Find Third Non-Repeated Character

41. Find First Repeating Character from a String

42. find the longest string from an array of strings:

43. Remove Consecutive Duplicate From List of String