Question: Given a list of non negative integers, I would like to arrange them such that they form the largest number. Given [1, 20, 23, 4, 8], the largest formed number is 8423201. But I want to figure how the order of the variables in compareTo method influences the result of Arrays.sort. e.g, what's the difference between (s2 + s1).compareTo(s1 + s2) and (s1 + s2).compareTo(s2 + s1).

```
enter code here

private static class NumbersComparator implements Comparator<String> {
        @Override
        public int compare(String s1, String s2){
            return (s2 + s1).compareTo(s1 + s2);
        }
    }
String strs = {"1", "20", "23", "4", "8"};
Arrays.sort(strs, new NumbersComparator());

```

Answer: 
Sort the numbers with reverse (*descending*) [lexicographical order](https://en.wikipedia.org/wiki/Lexicographical_order), that is the numbers are sorted with `String`(s) in the default *reverse order*. Like,

```
String[] strs = { "1", "20", "23", "4", "8" };
Stream.of(strs).sorted(Comparator.reverseOrder()) // <-- sort in reverse order
    .forEachOrdered(System.out::print);
System.out.println();

```

Which outputs

```
8423201

```

Because `8` is greater than the first digit of all the other numbers, `4` is the next, and so on.
Yes. The order in compareTo method will makes a difference. When you use compareTo method for string it compares the Unicode values of each character in a string and return the difference of two character value from the strings. 
For example,

```
System.out.println("abdc".compareTo("abcd"));

```

will return the difference of 'd'-'c'

```
Output : 1

```

and,

```
System.out.println("abcd".compareTo("abdc"));

```

will give difference of 'c'-'d'

```
Output : -1

```

Overall, the order matters as it returns the difference in certain way, that is:

```
thisString.charAt(index) - argumentString.charAt(index);

```