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

Signs and symptoms of a drug overdose include losing consciousness, fever or sweating, breathing problems, abnormal pulse, and changes in skin color.

Did you know?

Colchicine is a highly poisonous alkaloid originally extracted from a type of saffron plant that is used mainly to treat gout.

Did you know?

Your skin wrinkles if you stay in the bathtub a long time because the outermost layer of skin (which consists of dead keratin) swells when it absorbs water. It is tightly attached to the skin below it, so it compensates for the increased area by wrinkling. This happens to the hands and feet because they have the thickest layer of dead keratin cells.

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?

When taking monoamine oxidase inhibitors, people should avoid a variety of foods, which include alcoholic beverages, bean curd, broad (fava) bean pods, cheese, fish, ginseng, protein extracts, meat, sauerkraut, shrimp paste, soups, and yeast.

For a complete list of videos, visit our video library