Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- ArrayList<Tuple> arr = new ArrayList<>();
- arr.add(new Tuple(1, 2, 3));
- arr.add(new Tuple(1, 2, 100));
- arr.add(new Tuple(1, 2, 1));
- Collections.sort(arr);
- for (Tuple tp : arr) {
- System.out.println(tp.first + " " + tp.second + " " + tp.third);
- }
- }
- static class Tuple implements Comparable<Tuple> {
- int first;
- int second;
- int third;
- Tuple(int first, int second, int third) {
- this.first = first;
- this.second = second;
- this.third = third;
- }
- @Override
- public int compareTo(Tuple other) {
- if (this.first < other.first) {
- return -1;
- }
- if (this.second < other.second) {
- return -1;
- }
- if (this.third < other.third) {
- return -1;
- }
- return 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement