How to sort list by two fields in Java?

private static void order(List persons) { Collections.sort(persons, new Comparator() { public int compare(Object o1, Object o2) { String x1 = ((Person) o1).getName(); String x2 = ((Person) o2).getName(); int sComp = x1.compareTo(x2); if (sComp != 0) { return sComp; } Integer x1 = ((Person) o1).getAge(); Integer x2 = ((Person) o2).getAge(); return x1.compareTo(x2); } }); }

Form Tag

The Element The HTML element defines a form that is used to collect user input: . form elements . An HTML form contains form elements. Form elements are different types of input elements, like text fields, checkboxes ,radio buttons, submit buttons, and more. The Element The element is the most important form element. The element […]

Line Break Tag

Whenever you use the element, anything following it starts from the next line. This tag is an example of an empty element, where you do not need opening and closing tags, as there is nothing to go in between them. The tag has a space between the characters br and the forward slash. If you […]

Paragraph Tag

The tag offers a way to structure your text into different paragraphs. Each paragraph of text should go in between an opening and a closing tag as shown below in the example − Example: Paragraph Example Here is a first paragraph of text. Here is a second paragraph of text. Here is a third paragraph […]