List<Student> studentList = Stream.
of(
new Student(1, "Rohit", 30, "Male", "Mechanical Engineering", "Mumbai", 122,
[Link]("+912632632782", "+1673434729929")),
new Student(2, "Pulkit", 56, "Male", "Computer Engineering", "Delhi", 67,
[Link]("+912632632762", "+1673434723929")),
new Student(3, "Ankit", 25, "Female", "Mechanical Engineering", "Kerala", 164,
[Link]("+912632633882", "+1673434709929")),
new Student(4, "Satish Ray", 30, "Male", "Mechanical Engineering", "Kerala", 26,
[Link]("+9126325832782", "+1671434729929")),
new Student(5, "Roshan", 23, "Male", "Biotech Engineering", "Mumbai", 12,
[Link]("+012632632782")),
new Student(6, "Chetan", 24, "Male", "Mechanical Engineering", "Karnataka", 90,
[Link]("+9126254632782", "+16736784729929")),
new Student(7, "Arun", 26, "Male", "Electronics Engineering", "Karnataka", 324,
[Link]("+912632632782", "+1671234729929")),
new Student(8, "Nam", 31, "Male", "Computer Engineering", "Karnataka", 433,
[Link]("+9126326355782", "+1673434729929")),
new Student(9, "Sonu", 27, "Female", "Computer Engineering", "Karnataka", 7,
[Link]("+9126398932782", "+16563434729929", "+5673434729929")),
new Student(10, "Shubham", 26, "Male", "Instrumentation Engineering", "Mumbai",
98, [Link]("+912632646482", "+16734323229929")))
.collect([Link]());
class Student {
private int id;
private String firstName;
private int age;
private String gender;
private String dept;
private String city;
private int rank;
private List<String> contacts;
}
● Find the list of students whose rank is in between 50 and 100
● Find the Students who stays in Karnataka and sort them by their names
● Find all departments names
● Find all the contact numbers
● Group The Student By Department Names
● Find the department who is having maximum number of students
● Find the average age of male and female students
● Find the highest rank in each department
● Find the student who has second rank
1. TO Count the occurrence of each character in a string
2. TO Find all duplicate element from a given string
3. First non-repeating character
4. To find the second largest from an array
5. To find the longest string in an list/array
6. to find max number in array
7. to find the element start with 1
8. [Link] example
9. skip and limit methods
1. Lambda Expressions
Scenario Question:
You are working on a billing system where you need to sort a list of Invoice
objects based on their amount. How would you implement sorting using Java 8
features?
🔹 2. Functional Interfaces
Scenario Question:
You want to pass a behavior to a method (like a strategy) to calculate a discount on
different types of users (e.g., student, premium). How would Java 8 help you avoid
multiple classes or interfaces?
🔹 3. Streams API
Scenario Question:
In a library system, you have a list of books. You need to:
● Filter out books with less than 200 pages
● Convert the titles to uppercase
● Sort by title
● Collect into a new list
🔹 4. Optional
Scenario Question:
In a user authentication system, sometimes the user’s profile picture might not be
available. How would you safely handle the null scenario using Java 8?
🔹 5. Method References
Scenario Question:
You have a list of Employee objects and want to print their names. Instead of using
a lambda, how can method reference simplify this?
🔹 6. Default & Static Methods in Interfaces
Scenario Question:
You’re designing a Vehicle interface. By default, all vehicles should implement a
start() method with some basic logic. But you also want to have a utility method
isMotorized() as a static method. How can you do that in Java 8?
🔹 7. Date & Time API ([Link])
Scenario Question:
In an HR app, you need to calculate the number of days between an employee's
joining date and today. How would you do that in Java 8?
🔹 8. Collectors & Grouping
Scenario Question:
You are building a sales dashboard. How would you group all transactions by
customerId using Java 8 streams?