-2

I have an ArrayList in the form ArrayList<String[]> table_list = new ArrayList<String[]>();

So for example table_list.get(0) would look like {"Title", "Yes", "No"}.

Now let's say I have a lot of titles and want tot sort those titles in my table alphabetically, what do I do? Collections.sort() does not seem to work.

Thanks.

nTuply
  • 1,364
  • 19
  • 42
  • 1
    Your list shouldn't contain string array but instance of your class like Book, or whatever it represent. It would be more readable and easier to work with. – Pshemo May 20 '18 at 14:23
  • 1
    "Collections.sort() does not seem to work." is strange since it is one of ways to solve the problem. If it doesn't work for you then possibly you are misusing it, or problem is placed somewhere deeper (maybe your arrays doesn't contain what you assume). To get better help (in case provided answer and linked duplicate still doesn't solve your problem) use [edit] option and provide [mcve] which we could use to actually reproduce your problem along with description of what what problem is (error/exception/incorrect result vs expected result). – Pshemo May 20 '18 at 14:27

1 Answers1

2

pass a custom comparator:

table_list.sort(Comparator.comparing(e -> e[0]));
Ousmane D.
  • 54,915
  • 8
  • 91
  • 126