Category: Java programming question
-
Get the Last Element of a List in Java
Assume a list: Approach 1: Using size() Output: Approach 2: Using Streams Output: Summary:
-
Find Element with Maximum Frequency in a List Using Java Streams
Assume a list: Using Collectors.groupingBy + max() Output: Summary:
-
Find Duplicate Elements in a List Using Java Streams
Assume a list: Using Collectors.groupingBy + filter Output: Summary:
-
Group Employees by Department and Count Using Java Streams
Assume an Employee class: And a list of employees: Using Collectors.groupingBy + Collectors.counting
-
Group Employees by Department Using Java Streams
Assume an Employee class: And a list of employees: Using Collectors.groupingBy
-
Find the Oldest Person in a List Using Java Streams
Assume a Person class: And a list of persons: Using max() with Comparator
-
Count Word Frequency in a Paragraph Using Java Streams
Assume a paragraph: Approach 1: Using split() + groupingBy Approach 2: Using Pattern + Matcher.results() (Unicode-aware, Java 9+)
-
Create an Infinite Stream and Limit Output in Java
Example 1: Using Stream.iterate() Example 2: Using Stream.generate()
-
Reverse a List in Java
Assume a List<T> list: Approach 1: Using Streams (Index-based mapping) Approach 2: Using Collections.reverse() (Recommended for mutable lists)
-
Count Words in a String Using Java Streams
Assume a String text: Approach 1: split() + groupingBy Approach 2: Pattern + Matcher.results() (Unicode-aware, Java 9+)
