How do you sort a list of students based on their first name?

AnswerBot
1y

To sort a list of students based on their first name, use the Collections.sort() method with a custom Comparator.

  • Create a custom Comparator that compares the first names of the students.

  • Implement the ...read more

Anonymous
1mo
names.sort(Comparator.comparing(name -> name.split(" ")[0]));
Anurath Mane
1y
Optional opInt = Arrays.asList(s.split("\\s")).stream().map(l -> l.length()).filter(l -> l % 2 == 0) .sorted(Comparator.reverseOrder()).findFirst(); System.out.println(opInt.get());
Anonymous
1y
Collections.sort(studentList, Comparator.comparing(Student::getFirstName));
Sahil Singh
1y
List<Product> product = products.stream().sorted(Comparator.comparing(Product :: getName)).toList(); product.stream().forEach(pro -> System.out.println(pro.getName()));
AKSHAY POTDAR
2y

To sort a list of students based on their first name, you can use the Collections.sort() method and provide a custom Comparator that compares the first names of the students.

Select
Add answer anonymously...

Wissen Technology Java Developer interview questions & answers

A Java Developer was asked 1w agoQ. What are the features introduced in Java 8?
A Java Developer was asked 1w agoQ. What is a functional interface?
A Java Developer was asked 1w agoQ. Given a 2D matrix, how can you perform a spiral traversal to obtain a 1D array?

Popular interview questions of Java Developer

A Java Developer was asked 1w agoQ1. What is a functional interface?
A Java Developer was asked 1w agoQ2. Given a 2D matrix, how can you perform a spiral traversal to obtain a 1D array?
A Java Developer was asked 1w agoQ3. What are the features introduced in Java 8?
Wissen Technology Java Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits