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

Throughout history, plants containing cardiac steroids have been used as heart drugs and as poisons (e.g., in arrows used in combat), emetics, and diuretics.

Did you know?

Most fungi that pathogenically affect humans live in soil. If a person is not healthy, has an open wound, or is immunocompromised, a fungal infection can be very aggressive.

Did you know?

Bacteria have been found alive in a lake buried one half mile under ice in Antarctica.

Did you know?

People who have myopia, or nearsightedness, are not able to see objects at a distance but only up close. It occurs when the cornea is either curved too steeply, the eye is too long, or both. This condition is progressive and worsens with time. More than 100 million people in the United States are nearsighted, but only 20% of those are born with the condition. Diet, eye exercise, drug therapy, and corrective lenses can all help manage nearsightedness.

Did you know?

The first successful kidney transplant was performed in 1954 and occurred in Boston. A kidney from an identical twin was transplanted into his dying brother's body and was not rejected because it did not appear foreign to his body.

For a complete list of videos, visit our video library