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 603 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?

After a vasectomy, it takes about 12 ejaculations to clear out sperm that were already beyond the blocked area.

Did you know?

The term pharmacology is derived from the Greek words pharmakon("claim, medicine, poison, or remedy") and logos ("study").

Did you know?

As many as 20% of Americans have been infected by the fungus known as Histoplasmosis. While most people are asymptomatic or only have slight symptoms, infection can progress to a rapid and potentially fatal superinfection.

Did you know?

Urine turns bright yellow if larger than normal amounts of certain substances are consumed; one of these substances is asparagus.

Did you know?

Symptoms of kidney problems include a loss of appetite, back pain (which may be sudden and intense), chills, abdominal pain, fluid retention, nausea, the urge to urinate, vomiting, and fever.

For a complete list of videos, visit our video library