-3

I have List<String[]>. I would like to have it sorted by name in String[3] in alphabetic order. How should my comparator look like for such case ?

8
  • 1
    Have you tried anything? Commented Mar 22, 2013 at 6:38
  • "sorted by name in String[3]" - what exactly do you want ? Commented Mar 22, 2013 at 6:40
  • 1
    Collections.sort(List, Comparator). Note that I don't post an answer since it's your duty try something and then asking about the problems you have, not asking people to do things for you. Commented Mar 22, 2013 at 6:41
  • 1
    @Dukeling want to also give a cup of coffee and a cookie to OP while reading the answer he/she should have looked for? Commented Mar 22, 2013 at 6:43
  • 1
    Well I found it an interesting question. Not sure why so many downvotes. Commented Mar 22, 2013 at 6:48

1 Answer 1

3

try

    Collections.sort(list, new Comparator<String[]>() {
        public int compare(String[] o1, String[] o2) {
            return o1[3].compareTo(o2[3]);
        }
    });
Sign up to request clarification or add additional context in comments.

2 Comments

Oh, that is what the op was wanting... +1 from me. Still think the question was a dup though.
+1, what an elegant way of doing it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.