Problems
Basic Problems
Convert List to Uppercase
Given a List<String>, convert all elements to uppercase.
List<String> strList = List.of("Apple", "banana", "Orange", "Avocado");
List<String> strListUpperCase = strList.stream().map(String::toUpperCase).toList();Filter Even Numbers
Given a List<Integer>, filter out only even numbers.
List<Integer> intList = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
List<Integer> intListEven = intList.stream().filter(n -> n % 2 == 0).toList();Count Strings Starting with ‘A’
Given a List<String>, count how many strings start with ‘A’.
List<String> strList = List.of("Apple", "banana", "Orange", "Avocado");
long strListStartsWithA = strList.stream().filter(str -> str.startsWith("A")).count();Find Maximum Number
Find the maximum number in a List<Integer>.
Find Minimum Number
Find the minimum number in a List<Integer>.
Calculate Sum
Find the sum of all elements in a List<Integer>.
Check if All Elements are Positive
Verify if all numbers in a List<Integer> are positive.
Concatenate List of Strings
Join all strings in a List<String> using a comma.
Sort a List
Given a List<Integer>, sort it in ascending and descending order.
Remove Duplicates from List
Remove duplicates from a List<String>.
Intermediate Problems
Find Second Highest Number
Find the second-highest number in a List<Integer>.
Group Strings by Length
Group a List<String> based on string length.
Partition List into Even and Odd
Partition a List<Integer> into even and odd numbers.
Find First Non-Repeating Character
Find the first non-repeating character in a String.
Convert List of Strings to Map
Convert a List<String> into a Map<String, Integer> where the key is the string and the value is its length.
Find the Most Frequent Element
Find the most frequently occurring element in a List<Integer>.
Find the First Three Elements
Get the first three elements from a List<Integer>.
Find All Palindromes
Find all palindrome words in a List<String>.
Sort Employees by Salary
Given a List<Employee>, sort employees by salary in descending order.
Convert List of Strings to a Single String
Convert a List<String> into a single space-separated String.
Advanced Problems
Find the Longest Word
Find the longest word in a List<String>.
Find the Average Salary of Employees
Given a List<Employee>, calculate the average salary.
Group Employees by Department
Group employees into a Map<String, List<Employee>> based on department.
Find the Oldest Employee in Each Department
Find the oldest employee in each department.
Find Duplicate Elements in a List
Find all duplicate elements in a List<Integer>.
Convert a List of Employees into a Map
Convert List<Employee> into Map<Integer, String> where key is employeeId and value is employeeName.
Find the Youngest Employee
Find the youngest employee in the company.
Find the Longest and Shortest Words in a Sentence
Given a sentence, find the longest and shortest words.
Find the Average Age of Employees by Department
Compute the average age of employees per department.
Count the Occurrences of Each Character in a String
Given a String, count occurrences of each character.
Flatten a List of Lists
Convert List<List<Integer>> into a flat List<Integer>.
Find Top 3 Highest Salaries
Find the top 3 highest salaries from List<Employee>.
Convert a List of Objects to JSON String
Convert List<Employee> into a JSON-like String.
Find All Employees Older Than 30 and Sort by Salary
Find employees older than 30 and sort them by salary.
Find the Median Salary
Compute the median salary from List<Employee>.
Sort a List of Employees by Multiple Criteria
Sort List<Employee> first by department, then by salary.
Find the First N Prime Numbers
Generate the first N prime numbers using Stream.iterate().
Calculate Factorial Using Streams
Compute factorial of n using reduce().
Check if a String is an Anagram of Another String
Verify if two given strings are anagrams.
Find the Kth Largest Element in a List
Find the Kth largest number in a List<Integer>.
Generate a Fibonacci Series Using Streams
Generate Fibonacci numbers using Stream.iterate().
Find the Most Expensive Product in Each Category
Given a List<Product>, find the most expensive product in each category.
Find Most Common Words in a Paragraph
Given a String paragraph, count occurrences of each word and sort by frequency.
Merge Two Sorted Lists into One Sorted List
Merge two sorted lists into a single sorted list.
Check if a Sentence is a Pangram
Verify if a sentence contains every letter of the alphabet at least once.
Find the Sum of All Even-Indexed Elements in a List
Sum all even-indexed elements in a list.
Simulate a Voting System Using Streams
Given a list of votes, count occurrences of each candidate and determine the winner.
Last updated