Sorting ArrayList of Arraylist in java

后端 未结 7 982
忘掉有多难
忘掉有多难 2021-01-19 03:16

I have an ArrayList of ArrayList of String.

In Outer ArrayList on each index each Inner ArrayList has four items have four parameters.

  1. Contacts Id
相关标签:
7条回答
  • 2021-01-19 04:01

    You should create a class for your data structure (if you can't, then specify why. I can't see any good reason not to):

    public class Contact implements Comparable {
        private String id;
        private String name;
        private String address;
        private String number;
    
        // Getters and setters, and compareTo.
    }
    

    Then use that in your list instead:

    List<Contact> contacts = new ArrayList<Contacts>();
    

    Sorting it will then be trivial.

    0 讨论(0)
提交回复
热议问题