Last active
August 20, 2017 03:59
-
-
Save nullset2/f9d3c655bc581968495ca6f38065eecd to your computer and use it in GitHub Desktop.
ArrangeToGreater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Comparator; | |
class ArrangeToGreater{ | |
private static Integer[] numbers = {5, 2, 1, 9, 50, 56}; | |
public static void main(String[] args){ | |
Arrays.sort(numbers, new Comparator<Integer>() { | |
@Override | |
public int compare(Integer l, Integer r) { | |
String v1 = l.toString(); | |
String v2 = r.toString(); | |
return (v1 + v2).compareTo(v2 + v1) * -1; | |
} | |
} ); | |
String result = ""; | |
for(Integer integer: numbers){ | |
result += integer.toString(); | |
} | |
System.out.println(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment