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 ?
            Asked
            
        
        
            Active
            
        
            Viewed 102 times
        
    -3
            
            
        
        Luiggi Mendoza
        
- 85,076
 - 16
 - 154
 - 332
 
        Datenshi
        
- 1,191
 - 5
 - 18
 - 56
 
- 
                    1Have you tried anything? – Bernhard Barker Mar 22 '13 at 06:38
 - 
                    "sorted by name in String[3]" - what exactly do you want ? – Sudhanshu Umalkar Mar 22 '13 at 06:40
 - 
                    How would you do it for `List
`? – Rohit Jain Mar 22 '13 at 06:40 - 
                    1[`Collections.sort(List, Comparator)`](http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#sort(java.util.List,%20java.util.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. – Luiggi Mendoza Mar 22 '13 at 06:41
 - 
                    [Close enough](http://stackoverflow.com/questions/4699807/sort-arraylist-of-array-in-java)? Took me about 10 seconds to find. – Bernhard Barker Mar 22 '13 at 06:42
 - 
                    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? – Luiggi Mendoza Mar 22 '13 at 06:43
 - 
                    1Well I found it an interesting question. Not sure why so many downvotes. – Mar 22 '13 at 06:48
 - 
                    @djaqeel Because: 1) [Googling it](https://www.google.com/search?q=java+sort+list+of+arrays) instantly gives you a solution. 2) OP hasn't appeared to try anything (which probably isn't that good a reason in this case). – Bernhard Barker Mar 22 '13 at 07:00
 
1 Answers
3
            try
    Collections.sort(list, new Comparator<String[]>() {
        public int compare(String[] o1, String[] o2) {
            return o1[3].compareTo(o2[3]);
        }
    });
        Evgeniy Dorofeev
        
- 133,369
 - 30
 - 199
 - 275
 
- 
                    Oh, **that** is what the op was wanting... +1 from me. Still think the question was a dup though. – beatgammit Mar 22 '13 at 06:58
 -