Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Give the Java SE program below: import java.util. * ; class Name { private String first , last; Name ( String f , String l

Give the Java SE program below:
import java.util.*;
class Name{
private String first , last;
Name(String f, String l){first f; last=l;}
Name(){}
@Override public String toString(){ return first ++last;}
public static int compareByLastName(Name n1, Name n2)
{
return n1.last.compareTo(n2.last);
}
}
public class MethodRefTest{
public static void main(String[] args){
Name n1= new Name(Harry,Homeowner);
Name n2=new Name(Paul,Painter);
Name n3=new Name(Jane,Doe);
List nameList=Arrays.asList(n1,n2,n3);
******
Which of the following lines of code correctly substitute ****** to cause the program to compile and generate the output?
Jane Joe
Harry Homeowner
Paul Painter
a. nameList.sort(n1::compareByLastName);
nameList.forEach(System.out::println);
b. nameList.sort(Name::compareByLastName);
nameList.forEach(System.out::println);
c. nameList.sort(Name::compareByLastName);
nameList.forEach(System.out::println());
d. nameList.sort(Name::compareByLastName);
nameList.forEach(System.out.println);
e. nameList.sort(Name::compareByLastName);
nameList.forEach(System.out.println());

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago