This topic contains a solution. Click here to go to the answer

Author Question: What is the output of the following code?import java.util.*;public class Test { public static void ... (Read 602 times)

armygirl

  • Hero Member
  • *****
  • Posts: 556
What is the output of the following code?

import java.util.*;

public class Test {
public static void main(String[] args) {
ArrayList list = new ArrayList<>();
list.add(new Student("Peter", 65));
list.add(new Student("Jill", 50));
list.add(new Student("Sarah", 34));
Collections.sort(list);
System.out.print(list + " ");
Collections.sort(list, new StudentComparator1());
System.out.println(list);
}
 
static class StudentComparator1 implements Comparator {
public int compare(Student s1, Student s2) {
return s1.name.compareTo(s2.name);
}
}
 
static class Student implements Comparable {
String name;
int age;
Student(String name, int age) {
this.name = name;
this.age = age;
}

public int compareTo(Student s) {
return this.age - s.age;
}

public String toString() {
return "[" + name + ", " + age + "]";
}
}
}

◦ [[Jill, 50], [Peter, 65], [Sarah, 34]] [[Jill, 50], [Peter, 65], [Sarah, 34]]
◦ [[Sarah, 34], [Jill, 50], [Peter, 65]] [[Jill, 50], [Peter, 65], [Sarah, 34]]
◦ [[Sarah, 34], [Jill, 50], [Peter, 65]] [[Sarah, 34], [Jill, 50], [Peter, 65]]
◦ [[Jill, 50], [Peter, 65], [Sarah, 34]] [[Sarah, 34], [Jill, 50], [Peter, 65]]


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by armygirl on May 6, 2020

makaylafy

  • Sr. Member
  • ****
  • Posts: 347
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 39% of students answer this correctly




 

Did you know?

In Eastern Europe and Russia, interferon is administered intranasally in varied doses for the common cold and influenza. It is claimed that this treatment can lower the risk of infection by as much as 60–70%.

Did you know?

Today, nearly 8 out of 10 pregnant women living with HIV (about 1.1 million), receive antiretrovirals.

Did you know?

About 3.2 billion people, nearly half the world population, are at risk for malaria. In 2015, there are about 214 million malaria cases and an estimated 438,000 malaria deaths.

Did you know?

Barbituric acid, the base material of barbiturates, was first synthesized in 1863 by Adolph von Bayer. His company later went on to synthesize aspirin for the first time, and Bayer aspirin is still a popular brand today.

Did you know?

More than 50% of American adults have oral herpes, which is commonly known as "cold sores" or "fever blisters." The herpes virus can be active on the skin surface without showing any signs or causing any symptoms.

For a complete list of videos, visit our video library